Building a Hello World Web Part for Windows SharePoint Services 3.0
page 5 of 9
by Steven Barden
Feedback
Average Rating: 
Views (Total / Last 10 Days): 8833/ 284

Part 2: Developing The Web Part

1.    Open Visual Studio 2005 and start a new C# class library.

2.    Add a reference to System.Web.

3.    Add the following using statements at the top of your file.

Listing 1

using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;

4.    Rename your class to Hello by renaming the class file, which should rename that class name inside the file.

5.     Change the class to inherit from Web Part.

6.     Inside the class, override the base class RenderContents method.

7.     Replace the automatically added line referring to the base rendercontents method with your own content.

8.     To show the fact that you are programming in the ASP.NET model you may use one of the built in objects from the library.

9.     Below is an example of what the final product may look like.

Listing 2

using System;
using System.Collections.Generic;
using System.Text;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
 
namespace HelloWorldWebPart
{
    public class Hello : WebPart
    {
        protected override void RenderContents(HtmlTextWriter writer)
        {
            writer.Write(@"Hi, " + this.Context.User.Identity.Name);
        }
    }
}

View Entire Article

User Comments

Title: AWESOME   
Name: M.Czarnecki
Date: 11/2/2007 2:43:03 PM
Comment:
Absolutely fantastic.
You really reamoved all the bloat and the ridiculous hoops that MS wants us to go through. I don't have time for all that garbage. Your tutorial is a gem.

Product Spotlight
Product Spotlight 
Learn More
.NET Tools
asp.net shopping cart
asp.net chart control






Ads Powered by Lake Quincy Media
Community Advice: ASP | SQL | XML | Regular Expressions | Windows


©Copyright 1998-2008 ASPAlliance.com  |  Page Processed at 7/4/2008 5:35:25 PM  AspAlliance Recent Articles RSS Feed
About ASPAlliance | Newsgroups | Advertise | Authors | Email Lists | Feedback | Link To Us | Privacy | Search