Skip to content


Create Simple SharePoint Hello World WebPart And Add It To a Web Part Page

Not much work is needed to create a webpart in SharePoint (WSS or MOSS). I will show the simplest of webparts, so you can see how little work it takes.

1: Create a class library project, and add a reference to System.Web and Microsoft.SharePoint (rightclick “References” in “Solution Explorer”)

2: Create a batch (.bat) file to install in GAC

3: Sign the assembly (Properties on the project, bottom tab)

4: Add code (won’t be using actual SharePoint API, but you can do that as you wish, since we referenced SharePoint.dll)

01
using System;
02
using System.Web;
03
using System.Web.UI.WebControls;
04
using System.Web.UI.WebControls.WebParts;
05
using System.Web.UI;
06
 
07
namespace HelloWorldWebPart
08
{
09
  public class HelloWorld : WebPart
10
  {
11
    protected override void CreateChildControls()
12
    {
13
      base.CreateChildControls();
14
      this.Controls.Add(new LiteralControl("Hello, world! Welcome to Code-Journey.com"));
15
    }
16
  }
17
}
18

Remember to make the class public, otherwise you will not be able to add it to the SharePoint Web Part Gallery.

5: add safecontrol line to web.config

6: Go to the SharePoint Web Part Gallery (“Site Settings” and click “Web Parts” under the “Galleries” row.)

7: Click “New” in the top left corner.

8: Scroll through the list and check the “HelloWorldWebPart.HelloWorld” and click on “Populate Gallery”

9: Add the Web Part to any Web Part Page (try it on your front page) by clicking “Edit Page” in “Site Actions” menu. Click the “Add a Web Part” yellow link over the Web Part Zone you want to add it to.

10: A popup will appear. Click the + next to “All Web Parts” and and find the Web Part under Miscellaneous

DeliciousDiggTwitterFacebookLinkedInTechNetStumbleUponNewsVineTechnorati FavoritesSlashdotMSDNShare

Related posts:

  1. Repair broken Web Part Page in SharePoint / Remove Web Part From Page
  2. Make a SharePoint Application Page with CodeBehind
  3. How to create a new feature in sharepoint using Visual Studio
  4. How To Add A UserControl To A Web Part In SharePoint 2007
  5. The security validation for this page is invalid. Click Back in your Web browser…

Posted in SharePoint 2007.


0 Responses

Stay in touch with the conversation, subscribe to the RSS feed for comments on this post.



Some HTML is OK

or, reply to this post via trackback.



Page optimized by WP Minify WordPress Plugin