Important Tip: SharePoint 2010 Web Part Files and Descriptions

Before you create a Visual Web Part in SharePoint 2010, it is important that you understand the files that are included in a Visual Studio 2010 Web Part project.

SharePoint 2010 Web Part FilesAs you can see in the image on the left under “VisualWebPart1” the following files are included:

  1. Elements.xml: This file contains deployment instructions and the files that are needed to deploy the web part to the /_ControlTemplates folder of the SharePoint hive.
  2. VisualWebPart1.cs: This file simply hosts the ASP.Net user control used in the web part.
  3. VisualWebPart1.webpart: This XML file consists of the properties that describe the web part. You can add a Title, Description and an Error Message too. This file also make the web part visible in the web part gallery.
  4. VisualWebPart1UserControl.ascx: This file is the actual ASP.Net User Control that you edit in the Design mode of the Visual Studio 2010.

 

Some other important tips to keep in mind when developing new web parts:

  • It is important that you use the System.Web.UI.WebControls.WebParts.WebPart namespace instead of the older Microsoft.SharePoint.WebPartPages.WebPart;
  • Visual Web Parts can only be deployed as Farm Solutions, this is because a visual web part is deployed to the /_ControlTemplates folder and the web part needs farm permissions to access this folder;
  • The CreateChildControls function adds the ASP.Net User Control to the Controls collection of the web part class.
  • The VisualWebPart1.cs file consists of a private constant “_ascxPath” which consists of the path where the visual web part is installed in the SharePoint hive. Do not modify this path or rename anything, Visual Studio 2010 will do that for you;
  • A SharePoint 2010 web part page uses it’s own classes called SPWebPartManager and SPWebPartZone.

 

If you have any more tips you would like to share with our readers please feel free to leave a comment below.

Thank you.

Derek Halstead is a SharePoint consultant as well as the founder and principal of CertifiedSolutionsAustralia.com and CoolWriteups.com. He has 16 years of experience in the IT industry, with over ten years focused on Microsoft SharePoint. He can be reached by using the Contact Me link in the top menu.
Back to Top