Designing Web Parts with Visual Studio.NET
|Figure 6: The Web Part Template installer lets you choose a language.|
You can use Visual Studio .NET to build Web Part assemblies for use in SharePoint products and technologies. There are two options for building your Web Parts in Visual Studio: you can use the standard (provided) template for building a Web Control
gallery, or you can use a special template and build a Web Part
gallery. The Web Part gallery templates are not included with Visual Studio .NET, but you can download them from Microsoft at http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnspts/html/sharepoint_webparttemplates.asp
The templates are provided to help you create Web Parts and are very similar to the default server control file and project templates included with Visual Studio .NET. These templates are available for both Visual Basic .NET and C#. You choose the language you want when you run the template's setup program (see Figure 6
). Another piece of information you need to supply while installing the templates is the location of the Microsoft.SharePoint.dll file (see Figure 7
). On a computer running Windows SharePoint Services, the DLL is stored in local_drive:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\60\ISAPI.
Creating a project from the Web Part gallery templates offers advantages and features over using the standard Web Control gallery template, including:
- An automatic reference to the Microsoft.SharePoint.dll file
- A Web Part class file and a matching .dwp file
- A Web Part Manifest.xml file used during installation of the Web Part on the SharePoint server
|Figure 7: The Web Part Template installer requires you to enter the location of the Microsoft.SharePoint.dll.|
You will find the process of creating a Web Part very familiar if you have ever created an ASP.NET custom control. All the techniques for building an ASP.NET custom control also apply to building a Web Part custom control. The primary difference is that with a Web Part, you inherit from the WebPart class instead of from a WebControl class. You also need to override the RenderWebPart method instead of overriding the RenderContents method.
Additional information regarding developing Web Parts for SharePoint products and technologies is available in the SharePoint Products and Technologies Software Development Kit (SDK) available from MSDN (http://msdn.microsoft.com/sharepoint), and there are additional resources listed in the Related Resources section of this article.
Developing Web Parts is definitely not your grandfather's programming. Web Parts mean new opportunities, new horizons, and new challenges for developers providing a revolutionary capability for end users to customize their workspaces.
As always, I'm interested to hear your feedback about the material covered here.