Hello world SharePoint Web Part for Beginners
by Hojo Clement • March 22, 2010 • MOSS 2007 • 10 Comments
In this article we will see how we can develop a simple (Hello World) web part for SharePoint and create WSP.
Before starting the development, make sure that the following tools have installed.
1. Visual studio extension for windows SharePoint services:
http://www.microsoft.com/downloads/en/confirmation.aspx?familyId=7bf65b28-06e2-4e87-9bad-086e32185e68&displayLang=en
Note: You can refer the link http://www.allaboutmoss.com/index.php/2010/03/22/install-visual-studio-2005-extensions-in-windows-xp-or-vista/ for installing Visual studio extension in Windows XP
2. WSP Builder: http://www.codeplex.com/wspbuilder
Let’s get started. Fire up visual studio
Click File -> New -> Project
Choose the language (I am choosing c# for this tutorial) and select web part from visual studio template under SharePoint project type. Enter a web part name and click OK.
Visual studio, by default, creates a web part template with the folder named webpart1. Delete this web part and add a new one by
Right clicking the solution name -> Add -> new item.
Choose SharePoint, click web part and give the name as Hello_World. Click OK
Open the Hello_World.cs file
Change the base class of Hello_World.cs from System.Web.UI.WebControls.WebParts.WebPart
to
Microsoft.SharePoint.WebPartPages.WebPart
We will be overriding the RenderWebPart method. Add the following code.
protected override void RenderWebPart(HtmlTextWriter output)
{
output.Write("Hello World");
}
That’s it. Build your project and make sure there are no errors.
Next step is to build the WSP for this
Right click the Solution -> WSP Builder -> Build WSP.
Now you can see Hello_World web part in your project folder. In the next article we can see, how we can deploy this hello world web part.





Pingback: Webpart Development part 2: Deployment
Pingback: Creating Custom Web Part Properties
Pingback: Webpart Development part 3: Adding controls to web part
Pingback: Read data from a content editor webpart
Pingback: Peter Arblaster's SharePoint Blog
Hi, I have on my local pc,
-Visual Studio v8 – Installed to C;\ drive
-WSServices3.0_Tools Visual Studio 2008 Extensions_Version 1.2 – Installed to C;\ drive
-WSPBuilder – i.e.WSPBuilderExtensions.msi
I don’t have WSS installed on my PC because it has to be installed over ‘Win Server 2003’, right? (Maybe there’s a way I can install it locally??)
Our Sharepoint itself is installed on it’s own server available over the local network here. My task is to develop webparts and upload to this server.
Anyway, When I create the ‘Hello_world’ webpart project above and build it, I get the following compile error:
“The type or namespace name ‘SharePoint’ does not exist in the namespace ‘Microsoft’ (are you missing an assembly reference?)”
Quick google and I’m told Visual Studio is looking for a Microsoft.Sharepoint.dll file in,
C:\Program Files\Common Files\Microsoft Shared\web server extensions\12\ISAPI
..but on my local PC the ISAPI folder does not exist
How do I get it?
What program installs the missing .dll?
What am I missing here?
Any help gratefully received!!
Dan,
Copy the Microsoft.SharePoint DLL from the server to your project folder. Add reference and it should work.
Also you cannot install WSS in Windows xp/Vista/Win 7.. how ever if you are using Vista/Win 7 you can install MOSS 2010. Let me know it goes.
Hi Shoban,
Many thanks for the help here.
Curious, I copied over the .dll from the server to my local ‘Projects’ folder and then added a new Reference to it. However, it’s name (i.e. it’s identity) came through as Microsoft.Office.Server……I expected it to be Microsoft.Sharepoint.
Anyway I rebuilt the project but still got the same error report.
My compile errors are as a result of 3 lines of code,
using Microsoft.SharePoint;
using Microsoft.SharePoint.WebControls;
using Microsoft.SharePoint.WebPartPages;
I think I may have to make a connection between my local copy of Visual Studio and the WSS server…maybe by adding a Service Reference?
Are you sure you copied Microsoft.SharePoint dll? yes you will need connectivity to WSS site.
What exactly is your program doing? Is it a webpart? Have you installed SharePoint Extensions?
Hi I managed to get a copy of the ISAPI folder off the correct MOSS/WSS server. I copied it locally to,
C:\Program Files\Common Files\Microsoft Shared\web server extensions\12
…and added a reference to the Microsoft.Sharepoint.dll
This time no compile errors!! Thanks!