Assuming I have a SharePoint site ready to go, I will be using
My Site for Office SharePoint Portal Server 2003 for my example. (NOTE: I
will be creating links in this document to screen shots to help clarify what I'm
writing about).
- Install the
Web Part Templates for Visual Studio .NET
- Start Visual Studio and create a new C# Web Part Project named
HelloWebPartLib as
illustrated.
- Visual Studio will automatically create several files for you. Delete
the files: WebPart1.cs and WebPart1.dwp.
- Add a Web Part class to the project named HelloWorld.cs as
illustrated.
- Add a new Web Part DWP item to the project named HelloWorld.dwp as
illustrated.
- In the Properties window for the DWP file, set the Build Action property
to "Content". This will be needed later when you build a CAB file for
deployment.

- Create a new key pair using sn.exe so you can give the HelloWebPartLib a
strong name as
illustrated.
For example: sn -k c:\keypair.snk
- Edit the AssemblyInfo.cs file to change the AssemblyKeyFile attribute to
point to the key pair file you just created.
[assembly: AssemblyKeyFile("c:\\keypair.snk")]
- In the HelloWord.cs file, edit the RenderWebPart method to write out
"Hello World!"
protected
override void
RenderWebPart(HtmlTextWriter output)
{
//output.Write(SPEncode.HtmlEncode(Text));
output.Write("Hello World!");
}
- Build the HelloWebPartLib project.
- Now that you have built the project, we need to extract the
PublicKeyToken value of the assembly to specify in the HelloWorld.dwp file.
I use Lutz
Roeder's Reflector utility to pull this information, however you can use
sn -T from the Visual Studio command prompt as well.

- Edit the HelloWorld.dwp file so that the XML entity named <Assembly>
contains the PublicKeyToken value that you extracted using Reflector or
sn.exe. Also, add the TypeName value as shown below.
NOTE: Make sure you replace the highlighted public key token value in the
example below with your own!
<?xml
version="1.0" encoding="utf-8"?>
<WebPart
xmlns="http://schemas.microsoft.com/WebPart/v2" >
<Title>Hello World</Title>
<Description>Hello World WebPart</Description>
<Assembly>HelloWebPartLib, Version=1.0.0.0, Culture=neutral, PublicKeyToken=4a5727bcff5dd0bb</Assembly>
<TypeName>HelloWebPartLib.HelloWorld</TypeName>
<!-- Specify initial values for any additional base class or custom
properties here. -->
</WebPart>
- Edit the Manifest.xml file to specify the HelloWorld.dwp file in your
project. Note that you can simply alter the existing text that reads "<DwpFile
FileName="WebPart1.dwp"/>" and change it to the following:
<DwpFile
FileName="HelloWorld.dwp"/>
- Now we are ready to deploy our Web Part. The easiest way to do so is to
create a CAB project.
- Right-click on your solution and then click Add New Project.
- As
illustrated, create a Setup and Deployment CAB project named
HelloWPCab.
- Right-click on the CAB project, point to Add, and then click Project
Output.
- When the Add Project Output Group dialog box appears, specify "primary
output" and "content files" and then click OK.
- Rebuild the entire solution. At this point a CAB file will have been
created in the project directory you specified when creating the CAB
project.
- To install our CAB file on the SharePoint server, copy the generated CAB
file to the server. For this example, I am copying to the C:\ drive of the
server.
- Once our CAB file has been copied over to the server, we can run the
SharePoint command-line administration tool named stsadm.exe. This will
deploy our CAB file containing the HelloWorld WebPart.
NOTE: The stsadm.exe file on the server is in C:\Program Files\Common
Files\Microsoft Shared\web server extensions\60\BIN\ by defult.
- As
illustrated, run the stsadm.exe utility using the following
parameters to install the HelloWorld WebPart. Note that you may need to
change the highlighted path below depending on where you copied the CAB file
on the server.
stsadm -o addwppack -globalinstall -force -filename
C:\HelloWPCab.cab
- As
illustrated, now you can add your WebPart to a SharePoint portal page!
In this case, I am adding it to the default page in "My Site". Do this by
clicking on the Modify My Page link, point to Add Web Parts, and then click
Browse.
- When you click on the Virtual Server Gallery link on the right window
pane, you will see the Hello World Web part available for use.

- Drag and Drop your Hello World WebPart into one of the available zones
as illustarted. That's it!
