Saturday, September 22, 2012

Building in SharePoint 2007 with Visual Studio 2008

 SharePoint 2010   SharePoint has been over the years growing in popularity for connecting Microsoft Visual Studio applications to people and process. It is a collaboration software for enterprises, as dubbed by Microsoft. It is used by developers, IT professionals and end users for efficient sharing of website content developed without training and in minimum timeframe. Fortune 500 companies have often used fast and friendly technologies like SharePoint with Visual Studio to develop and collaborate in social networks for employees. Hence it remains chiefly a corporate venture.  

How to build Visual Web Parts for SharePoint 2007

SharePoint 2010 Enterprise - 'Create Site' screen

This article covers a basic tutorial on how to build Visual Web Parts for SharePoint 2007 as shown in the link https://vimeo.com/11285888 .   

The main steps to follow are : 

  1. First create a sample empty website with Visual Studio 2008 and check that the browser and web server are working correctly displaying it. The web server is IIS Server. Any browser should be compatible. 
  2. Create a new project. Select WSPBuilder as the project. If you have installed SharePoint, the WSPBuilder option will come under Workflow projects under Visual C # or Visual Basic Language projects group. Change the name of the new project to something you want. 
  3. You get the project solutions explorer to list project files. Select the project name and right click to add new item. You can add windows forms, web forms, reporting, data and code object items. But in the WSPBuilder Items, there are many features like Web Part Feature, Sequential Workflow feature and State Machine feature alongwith event handler and other item templates. Select the Web Part Feature and Add. 
  4. In the feature settings, set the scope of the Web Part to site, since we would be adding the web part to the site. Also you may need to rename the feature and add description. 
  5. Now you get the feature folder having the manifest XML file of feature and elements. Also you get the CodeBehind file where you can add and manipulate data to be bound and displayed into the site. 
  6. Add GUIDType in the csproj Project File. The details are given in next section. This is to certify all .NET Web Forms to go with older VS 2008, so that after registering the new assembly with GUIDType in Project File, you can add VS 2010 Web User Control Items from Add Item templates. 
  7. Now Design a View Page with Data Controls. 
  8. Add/Edit Event Handlers of Controls. 
  9. Add your custom code to event handler. For example databind the datasources of data objects. 
  10. Now clear and recode the WebParts CodeBehind file. It has sample code as inherited from Microsoft Sharepoint Library. On the same namespace, inherit the WebPart Item class from System.Web.UI.WebControls.WebPart . 
  11. Now you need to load the WebPart Control file WebPartUserControl.ascx . For which you just need to specify the relative path of your control file among the control templates inside your project. 
  12. Build the project so that Assembly dll is created. 
  13. Now you must add an assembly reference to the project dll file inside the User Control ASP code. For that use Reflection.exe drag drop the assembly created for your project. It will reflect the four part assembly reference which you copy paste in the ASP code of Visual Web Part User Control .ascx file. 
  14. Now build and deploy. Refresh your site and the Sharepoint Site has this new user control added for activation. 
  15. Activate the Web Part and use your site with new control behaviour.      

No comments:

Post a Comment