Skip to main content

Cloud

WebParts 1, 2, 3, Go:

What the books say

To develop a WebPart the best place to start is to download the SharePoint Templates, a VS.Net project template that creates a basic project with all the files needed to get your code into SPS as a fully qualified WebPart.

http://www.microsoft.com/Downloads/details.aspx?familyid=CAC3E0D2-BEC1-494C-A74E-75936B88E3B5&displaylang=en

After you install the template create a new project and select the new Web part Library template. I use C# only the code syntax differs for my friends in VB.Net land.

(check this C# to VB.Net translator out – it’s very good: http://www.ragingsmurf.com/vbcsharpconverter.aspx )

In solution explorer notice the following files:

  • Manifest.xml – used to identify the component pieces of the project namely the namespace and the strongly named assembly in addition to the .dwp file.
  • WebPart1.dwp – identifies the namespace, assembly and the name of the WebPart as it will appear within SharePoint configuration.
  • WebPart1.cs – contains public property code, private methods and an overridden RenderWebPart() method.

As mentioned in a previous blog, SharePoint runs with a high level of security and so must any component code that runs within, and this includes WebParts. For this reason your WebPart code must be strongly named i.e. signed. This is achieved by creating a Private-Public key pair file (.snk) described here;

http://msdn2.microsoft.com/en-us/library/6f05ezxy.aspx

Reference the .snk file in the AssemblyInfo.cs file as described in the article.

Whatever names are used for the class file, namespace or assembly must be reflected in the .dwp files.

As will be described in a later blog, the assemblies public key is required by the SPS webpart installation process and needs to appear in the Manifest file as follows:

<Assembly>AssemblyName,

Version=1.0.0.0, Culture=Neutral, PublicKeyToken=4aabc19c915ce666

</Assembly>

<TypeName>Namespace.Classname</TypeName>

The two main points of interest are:

  • Properties – What do those attributes do?

These attributes are used for the SharePoint webpart configuration page.

The Text property is required and all others are user specific.

They are very useful for setting up custom configurations.

  • RenderWebPart() method

This is where it all comes together.

This method either spits out the HTML itself and/or overrides its base CreateChildControls() method as necessary.

The parts and properties are well documented in numerous articles and blogs.

Check out these links as good examples.

http://msdn.microsoft.com/msdnmag/issues/04/08/webparts/default.aspx

http://www.u2u.net/Article.aspx?ART=msdnsharepoint1

The next step after building your webpart is to install it into SharePoint, a process worthy of its own blog…………

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Aaron Steele

More from this Author

Follow Us