Wednesday, January 27, 2010

Visual Web Part in SharePoint 2010

There is a new web part template in Visual Studio 2010, that actually lets you develop and deploy user controls by packaging all in a single unit.  Lets take a look at what this single unit contains when you create the project:

image

- The “properties” and “Reference” are the similar standard folders created for all projects.

- The “Features” is a new folder that contains the configuration information for the feature.

- The “Package” is also a new folder that contains the configuration information for the WSP.

- The last folder (in my case “VisualWebPart1”, this is the name that you provide during the project creation) is the standard user control project template folder structure. It hosts a number of files: a .cs file, a .webpart file, an elements.xml file, and a .ascx file. 

So actually it creates an ASP.NET user control and the VS 2010 lets you open the designer for the user control already wrapped within the web part.

This is not very different than what we used to do earlier by creating to separate projects in a single solution – one for the web part and the other for the user control. Then the web part would actually embed the user control by issuing the command Page.LoadControl() method pointing at the user control. 

So VS 2010 has done a great job to hide a lot of tasks from the developers by bringing many pieces together at one place and packaging as a single unit for an easy deployment to SharePoint.