Developing Web Parts for MOSS is easy!

By | March 16, 2010

In this post I will show you how easy it is to develop webparts in MOSS (Sharepoint), If you know how to develop in .Net then it will be a breeze.  It will be as easy as 13 steps so here we go.

Step 1

Create a new Class Library Project and name it any way you want I named mine as MyWebPart

Class Library Project


Step 2

You now add a reference to System.Web as you are using the following namespaces

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

You can do that by right clicking on the project and choose add a reference, choose the .Net tab

Add Reference

Do you coding now.  Here is a sample code on how to render controls on the webpart

namespace MyWebPart
{
    public class NewWebPart : WebPart
    {
        protected override void CreateChildControls()
        {
            TextBox myTextBox = new TextBox();
            myTextBox.Text = "This is easy";
            Controls.Add(myTextBox);
        }
        public override void RenderControl(HtmlTextWriter writer)
        {
            RenderChildren(writer);
        }
    }
}

On this sample its just a simple rendering of a TextBox called myTextBox and assigning a value to the textbox.  Once done you are ready to publish the code to your MOSS


Step 3

Determine the bin folder of your MOSS site, you can find it in IIS. Usually its in C:InetpubwwwrootwssVirtualDirectories{your MOSS instance name}bin

MOSS bin folder


Step 4

Once found, copy and put that in your output path in the build properties of your project, also choose All configurations on the Configuration Section, so when you debug it publishes on your MOSS bin folder (not a best practice but we just doing it for simplicity if this walkthrough)

Output Path build properties


Step 5

Build the project and you will now see the dll on the MOSS bin folder

 

 


Step 6

Add a SafeControl Assembly on the web.config of your MOSS instance.  That would be one directory above the bin folder.

Safe Control Assembly


Step 7

Now that your webpart is on the server you need MOSS to import the library you created for you, you can do that by going to Site Settings and Modify Site Settings

Site Actions


Step 8

Now go to Galleries and choose Web Parts

Web Part Galleries


Step 9

Add the WebPart by clicking New

New Web Part


Step 10

Choose the webpart you just developed by ticking the checkbox beside it and click Populate Gallery

Populate Gallery


Step 11

Now your new webpart is available for use in any of you pages and it is now included in the library

New WebPart


Step 12

Now you can use it in any pages, if you add a new webpart it will be on the list

Web Part List


Step 13

Now you can use it. its that simple!’

Finshed Product

Recommended

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.