Overview
The following will help you to quickly create a new sharepoint webpart, deploy it, activate it, and place it on a page in your sharepoint site.
Before you begin, ensure that you have a test WSS site set up, and the permissions necessary to alter it.
Install the VS templates
Microsoft recently released a set of additions to Visual Studio 2005, called the WSS 3.0 Tools: VS 2005 Extensions. You can download these here. Once installed, a number of new project templates will be available in Visual Studio 2005.
Create your project
Once you have installed the additions, open Visual Studio 2005, and create a new project. From the available project types, select Visual C#->Sharepoint. Now, select “Web Part” from the available templates.
Give your project a name, and click ‘Ok’.
In the Solution Explorer view, navigate to the root of your newly created project, right click, and select properties.
Select the ‘debug’ tab on the left hand side of the property view. Navigate to the “Start Browser with URL:” textbox, and insert the url of your test site. If the home page of your test site is http://wsstestsite/sites/new/default.aspx, enter http://wsstestsite/sites/new/
Save these updated properties, and press F5 (or, right click on your project in solution explorer, and select ‘deploy’).
If everything has gone smoothly, the toolbar in Visual Studio will state the Deploy has Succeded.
Write your webpart
In order to display content in your webpart, you need to finish the implementation given by the Render() stub.
This method includes a single HtmlTextWriter parameter, which you must use to output the html to be displayed in the webpart.
The simplest way of doing this is to create a String of html content, and then use the writer.write() method to write the html content.
As an example, you could enter the following code:
string sHtml = “Hey there “ + SPContext.Current.Web.CurrentUser.Name + “!”;
writer.Write(sHtml);
Once you have created and written your html string, deploy the solution again.
View your webpart
In order to view your webpart on your wss site, you will need to place the webpart on a page.
Open a web browser, and navigate to your test site.
Click on ‘site actions’, and select ‘edit this page’.
Once the page has entered editing mode, navigate to the right hand column of the page, and select ‘Add a Web Part’.
A window will now pop up, with the available Web Parts. Select the checkbox to the right of your webpart, and select ‘Ok’.
Your new webpart will now be inserted at the top of the right hand column.
Editing your webpart
Now that your webpart has been placed on the page, you may make any future changes in visual studio. After redeploying the webpart, you may view any changes in your web browser simply by refreshing.