What goes in the the type element of a .webpart file?

Creating a .webpart file

Creating a Web Part for SharePoint is basically the same as creating a generic ASP.Net web part. One of the keys in ASP.Net webpart development is creating a webpart definition file with the extension .webpart. In SharePoint, an easy way to create the base of your .webpart file is to add your webpart to the Web Part Gallery of any Site Collection and then export the .webpart XSL that SharePoint Generates for you.

Understanding the <Type name=”[your type name]”>

The type element of a .webpart file has a name attribute. The definitions of all elements of the .webpart file are found in MSDN’s ASP.Net Reference section because the .webpart file is not specific to SharePoint. As the MSDN article explains, the name attribute of the type tells .Net where to find your web part class and assembly. The attribute value starts with the name of the type, including the namespace. The name of the type is the same as the Class Name of the class you built that inherits from the .Net Framework WebPart Class. An optional part of the name attribute is the assembly name. It is optional, but it is the only way to fully describe your type, as described in the Common Type System Overview article on MSDN. Next, the version, culture and Public Key Token must be specified.

Example from a .Net Framwork WebControl


In this example, you can see that the BulletedList WebPart type is defined in the System.Web.UI.WebControls Namespace and the System.Web assembly includes it’s compiled code. The version, culture and PublicKeyToken values are all specified, as required.

Comparison to SafeControl Entry


Don’t fall into the trap of thinking the name attribute of the type element of a .webpart is the same as the Assembly Attribute of a Safe Control entry. The above example is from Brett Maytom’s description of a Safe Control entry of a web.config file. Notice that the Assembly Attribute of the SafeControl Element of the web.config contains the assembly name, version, culture and Public Key Token, but not the type, or class, name. Referencing an assembly this way is often referred to as using a four-part name for the assembly. Making sure this assembly name from web.config matches the same part of the name attribute in your .webpart file is top troubleshooting tip when you are unable to add selected web part(s). Just make sure that you specify your class name, including namespace before what is basically the assembly four part name.


Inside Microsoft Windows SharePoint Services 3.0

Pictured to the right is one of my go to SharePoint Development reference books lately, Inside Microsoft Windows SharePoint Services 3.0 by Ted Pattison and Daniel Larson. If you are developing for SharePoint 2007 and don’t have a copy of this book, I highly recommend it.image

Leave a Reply

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