Everything SharePoint and XAML

My continuous learning of SharePoint, XAML, Silverlight, Windows Phone 7, Windows 8, Office, VSTO, C#…

Part 1: Build Web Part Assembly

Posted by Steve Pietrek on June 6, 2007

This is Part 1 of a series on creating web parts and deploying them to SharePoint using a VS 2005 Solution Project. There are 6 parts in the series.

1. Open Visual Studio .NET 2005
2. Select File>New>Project from the menu
3. In the New Project dialog, select the Visual C# Project Type
4. Under Templates, select Class Library
5. Name the project HelloWorldWebPart
6. Check the “Create directory for solution” option
7. Name the Solution HelloWorldWebPart
8. Click OK
9. Right-click on Class1.cs and select Rename
10. Rename the file to HelloWorldWebPart.cs
11. Right-click on the HelloWorldWebPart and select Add Reference
12. Add the following reference to the project:

  1. System.Web

13. Add the following using statements to the HelloWorldWebPart.cs file:

  1. System.Web.UI
  2. System.Web.UI.WebControls
  3. System.Web.UI.WebControls.WebParts
  4. System.ComponentModel

14. Change the HelloWorldWebPart.cs file’s namespace to HelloWorld.Web
15. Add the following code to the file:



    public class HelloWorldWebPart : WebPart


        protected LiteralControl _info;


        private string _employeeName;


        [Personalizable(PersonalizationScope.User), WebBrowsable(true), Category(“Data”)]

        public string EmployeeName {

            get { return _employeeName; }

            set { _employeeName = value; }



        protected override void CreateChildControls() {



            _info = new LiteralControl(_employeeName);



            this.ChildControlsCreated = true;



        protected override void RenderContents(HtmlTextWriter writer) {

            writer.AddAttribute(HtmlTextWriterAttribute.Width, “100%”);

            writer.AddAttribute(HtmlTextWriterAttribute.Border, “0”);






            writer.RenderEndTag(); // td

            writer.RenderEndTag(); // tr




16. Build the HelloWorldWebPart project and fix any errors.


One Response to “Part 1: Build Web Part Assembly”

  1. […] Part 1: Build Web Part Assembly « Steve Pietrek’s SharePoint Stuff (tags: sharepoint webparts moss2007) […]

Sorry, the comment form is closed at this time.

%d bloggers like this: