Friday 12 October 2007

A Dummies guide to Creating a custom Web Part for SharePoint Server 2007

We have put together simple but important things about the development and deployment of web parts for Sharepoint server 2007.

1. Download the SharePoint Add on for Visual Stuido, this will create new templates so when you click on New Project in Visual Studio you will see new project types like "WebPart http://www.microsoft.com/downloads/details.aspx?FamilyID=19f21e5e-b715-4f0c-b959-8c6dcbdc1057&DisplayLang=en

2. Sharepoint web parts can be treated like Custom Server Controls in .Net. The difference is SharePoint references are added automatically when you create a new web part project and deploying to SharePoint is as easy as pressing F5.

3. Use the SharePoint object model classes like SPWeb, SPContext, SPListItemCollection and SPListItem to work with lists in Sharepoint. This way there is no need to add a web reference to the web service that is exposed by SharePoint.

4. Deploying - If Sharepoint is installed on the development machine then pressing F5 will automatically add the webpart in the GAC, mark the webpart as safe in the sharepoing web.config files and import the .dwp file into sharepoint. So to add the custom web part that we created, all we need to do is click Add web part and our custom web part should appear in the list of web parts along with other web parts.

5. When you run the project (F5) a setup.bat file is created in the Debug Folder or Release folder (depending on build type you do). Copy this folder accross to the server where you want to install this webpart and run the setup.bat file in the folder. Now this would do the steps mentioned in point 4 above so the webpart can be added to the sharepoint site by using the Add Web Part tab.

No comments: