Creating a WSS/MOSS Web Part – The Basics

Creating a WSS/MOSS Web Part – The Basics

I’ve created this simple guide to demonstrate the various files that you need to create and how to structure your Visual Studio solution in order produce a WSS/MOSS Web Part.

1) Create a new Class Library (dll) project in Visual Studio

2)Name your class file appropriately:

Visual Studio Solution Explorer

3)Add a reference to the Microsoft SharePoint dll and strongly sign the assembly (Project –> Properties –> Signing –> Sign the assembly)

4)Create the following folder structure in the solution:

Visual Studio Solution Explorer - Creating Project Structure

5)Create a folder under features with the name of your web part

6)Create the following files under the feature folder:

Visual Studio Solution Explorer - Creating Project Structure

7)Place the following code into the .webpart file:

[code lang="xml"]<webParts>
<webPart xmlns="http://schemas.microsoft.com/WebPart/v3">
<metaData>
<type name="DemoWebPart.DemoWebPart, DemoWebPart, Version=1.0.0.0, Culture=neutral, PublicKeyToken=ec278ac1962b4ce0" />
<importErrorMessage>Cannot import Custom CascadingNav Web Part.</importErrorMessage>
</metaData>
<data>
<properties>
<property name="Title" type="string">Demo Web Part</property>
<property name="Description" type="string">Demo Web Part</property>
</properties>
</data>
</webPart>
</webParts>[/code]

Where type name contains the namespace.classname and the full assembly name of your dll. Also set your title and description here.

8)Place the following code in the ElementManifest.xml file:

[code lang="xml"]<Elements xmlns="http://schemas.microsoft.com/sharepoint/">
<Module Name="WebParts" List="113" Url="_catalogs/wp" >
<File Url="DemoWebPart.webpart" Type="GhostableInLibrary" />
</Module>
</Elements>[/code]

Ensure that the ‘File Url’ matches the name of the webpart file created in step 6.

9)Put the following code in the Feature.xml file:

[code lang="xml"]<Feature Title="DemoWebPart" Id="74BE3173-91B7-4ef7-B50A-E31357885176" Description="" Version="1.0.0.0" Scope="Site" Hidden="FALSE" DefaultResourceFile="core" xmlns="http://schemas.microsoft.com/sharepoint/">
<ElementManifests>
<ElementManifest Location="ElementManifest.xml" />
<ElementFile Location="DemoWebPart.webpart" />
</ElementManifests>
</Feature>[/code]

Make sure you create a new GUID for the ID and specify the correct ElementManifest and ElementFile names.

10)Your Web Part is now ready, you can now add your code to the cs file. Once finished, build the solution, copy the dll to the GAC folder we created under the solution and build the WSP folder using the WSPBuilder tool (http://www.codeplex.com/wspbuilder).

Hope this helps! :-)

Leave a Reply

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

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code class="" title="" data-url=""> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre class="" title="" data-url=""> <span class="" title="" data-url="">