Creating a WSS/MOSS Web Part – The Basics

29 04 2009

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:

Untitled-1

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:

Untitled-2

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

6)Create the following files under the feature folder:

aa

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

<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>

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:

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

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:

<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>

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! 🙂

Advertisements

Actions

Information

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s




%d bloggers like this: