About these ads

Developing Web Parts for MOSS is easy!

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:\Inetpub\wwwroot\wss\VirtualDirectories\{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

About these ads

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Follow

Get every new post delivered to your Inbox.

Join 197 other followers

%d bloggers like this: