Creating a Web Part Using MOSS BIN DIRECTORY

1         Creating a Web Part Using MOSS BIN Directory

We will start from the Visual Studio 2005 new project window. In the new project window, we will select C# Window application and then, class library. We will name the project “HELLOBIN”.

1-2.jpg

1.1    Adding Reference

The first thing we will do in the class library is to add reference of the name space System.Web. This is done by right clicking on the References link in the solution explorer and then clicking on “Add Reference…”.

 

Clicking on add reference will generate a new pop up window Add Reference. We will select the System.Web namespace, as encircled in the figure below, and click on OK. It will add the System.Web namespace in our project and details of which can be seen in the Reference link.

  

2-2.jpg

   

We will add the names spaces, encircled red in the figure below, in our project so that we can directly use the classes in that namespace without specifying the complete path.

 

3-2.jpg

1.2   Changing Class Name

We will again go to the solution explorer and change the name our class from “Class1” to “HELLOBINCLASS”. This can be done by clicking on the class name in the solution explorer and right click on the class name. This will open a new window from which we will select Rename and change the class name from “Class1” to “HELLOBINCLASS”. As you change the name of the class, a prompt will appear, shown in the figure below, and ask would you like to rename all references to the code element “Class1”? Click Yes.

1.3   Inheriting Class

We will inherit our class from the class WebPart. The path to the class WebPart is System.Web.UI.WebControls.WebParts.WebPArt. We have already added the namespace System.Web.UI.WebControls.WebParts; therefore, we just right the name of the class WebPart for inheritance.

1.4   Overriding Method

We will create a simple program for demonstration purpose. The code will override a method Render. The exact code of the method is shown in the figure below.

4-2.jpg

1.5   Changing Output Path

After writing the code, we will change the out put path setting of the project. For this, we will right click on the project name in the solution explorer and then, we will click on the properties.

 

On clicking the properties, a new window will be appeared. We will select the build pane of the window as shown in the figure below. In the build pane, we will set the out path to the bin directory of the MOSS. In our case, the path is C:\Inetpub\wwwroot\wss\VirtualDirectories\80\bin which is encircled in the figure below:

 

5-2.jpg

1.6   Build Project

We will build by pressing F6 or clicking on Build in the tolls menu and then clicking on Build Solution. Build will generate the file HELLOBIN.dll in the bin directory.

 

1.7   Adding Reference

We have to add the reference to the web.config. The file will be located in the folder created by MOSS. In our case, the path of the file is C:\Inetpub\wwwroot\wss\VirtualDirectories\80. We will open the file in the Visual Studio and go to the tag <SafeControls>. Here we will add a new entry for our web part in the <SafeControls> tag which is <SafeControl Assembly=”HELLOBIN” Namespace=”HELLOBIN” TypeName=”*” Safe=”True” />, encircled in the figure below:

 

6-2.jpg

   

After writing the entry, don’t forget to save the web.config file. Becareful while making changes in the web.config file because if this file get corrupted, i am afraid you will be in big trouble. So workaround is that save a copy of file and then make changes so that you have orginal copy of the file intact.

1.8   Adding Web Part in the Web Part Gallery

Now we demonstrate the next phase of adding the web part in the sharepoint site. For this, click on the “Site Action” of your sharepoint main page and click on “Modify All Site Settings” by moving through “Site Settings”.

 

Site Settings page will be opened. Click on the link “Web Parts” under “Galleries”.

 

Web Part Gallery web page will be opened. Click on the “New” to add the web part in the gallery. Clicking on “New” will bring you the list of all the web parts and our web part HELLOCINCLASS will be available in the list. Select the Web Part “HELLOBIN.HELLOCINCLASS” (Name of the namespace followed by the name of the class) and click on the button “Populate Gallery” as shown in the figure below:

7-2.jpg

1.9   Adding Web Part on the Site

After adding the web part in the web part gallery, you can easily add the web part on the desired site. For this, click on the Site Action and then on Edit Page. The page will be open in the edit mode. Click on the link “Add a Web Part” in the space where you want to add the web part.

 

Clicking on “Add a Web Part” will result in a new window which will contain the list of all the web parts. From the list, select the web part you have created.

 

After adding the web part, click on the “Exit Edit Mode” and the web part will be working on the site.

   

   

Advertisements

2 Comments »

  1. […] Creating a Web Part Using MOSS BIN DIRECTORY « farhanfaiz’s Weblog […]

  2. ssa said

    Hey Farhan

    I just noticed your blog, I didn’t know it existed! 🙂 It seems you recently started blogging. Welcome to the blogging world! You can also announce the existence of your blog on the SharePointPUG group of which you are already a member. That will help increase the traffic to your blog. The content you posted is really good. Well done! Keep posting good tips and tricks!

    All the best

    SSA
    MOSS MVP
    http://sharepointblogs.com/ssa

RSS feed for comments on this post · TrackBack URI

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

%d bloggers like this: