Dotnetdreamer's Weblog

SharePoint, Silverlight and Azure

Posts Tagged ‘Web Parts’

Creating Custom Web Parts in MOSS 2007

Posted by Ramprasad Navaneethakrishnan on May 9, 2009

Over my previous posts, I was discussing about the out-of-the-box site templates and out-of-the-box webparts available in MOSS 2007. This post is dedicated to Creating Custom Web Parts in MOSS 2007.

Creating Custom Web Parts:

Let us list down the procedures involved in creating custom web parts.

  1. Create custom web part control in Visual Studio
  2. Strong name the created web part assembly
  3. Place the assembly in the bin directory in the Virtual Directory of the web application
  4. Place the assembly in the GAC
  5. Notedown the assembly name, version and public key token by looking into the assembly properties in the GAC
  6. Add a SafeControl entry for the web part assembly in the application’s web.config file
  • Create Web Part in Visual Studio
    • Open Visual Studio 2005–>Create New Project–>Select Class Library project template–>Enter the project name as CustomWebpart
    • customwebpart_vs_createproject
    • Add Reference to System.Web dll
    • Open Class1.cs. Add the following namespaces
      • using System.Web;
      • using System.Web.UI.WebControls;
      • using System.Web.UI.WebControls.WebParts;
    • Change the name of the class to CustomWebPart1. Inherit CustomWebPart1 from WebPart class (see code below)
    • Override CreateChildControls and RenderControls events (see code below)
    • Create a label control and assign its text property inside CreateChildControls events ( see code below)
    • The code looks like the following
    • using System;
      using System.Collections.Generic;
      using System.Linq;
      using System.Text;
      using System.Web;
      using System.Web.UI.WebControls;
      using System.Web.UI.WebControls.WebParts;

      namespace CustomWebpart
      public class CustomWebPart1 : WebPart
      Label lblName;
      protected override void CreateChildControls()
      lblName = new Label();
      lblName.Text = “This is the Custom Webpart created in MOSS training”;
      public override void RenderControl(System.Web.UI.HtmlTextWriter writer)


    • Build the solution.  The assembly CustomWebpart will get created


  • Strong Naming the Assembly
    • Go to Project Properties page (Right click the project and select properties)
    • Select Signings section.  Check the ‘Sign the assembly’ checkbox.
    • Select ‘Create New’ in the ‘Choose the strong name file’ drop down box.
    • In the dilog box enter a key name say snKey and click ok. (Uncheck the password checkbox).
    • customwebpart_vs_createstrongname
    • Now the assembly is strong named. Build the project.
  • Place the dll in the bin folder of the application’s virtual directory


  • Place the dll in the GAC and note down its name and public key token


  • Add the assembly as Safe Control in the application’s web.config.


  • Thats all. Do an IISRESET
  • Adding newly created web part to Site Collection
    • Go to SiteActions –>Site Settings
    • In the Galleries section choose Web Parts
    • In the Web Parts gallery click on New
    • In Add new web parts page, scroll through the list and select the web part you just created.
    • Click on the button Import Web Part to the Gallery.
    • Now, go to the page where you want to add the newly created custom web part
    • SiteActions –> Edit page
    • Click Add Web Part. In the Add Web Part box, select the custom web part.
    • Click Ok.
    • Now you can see the custom web part is added to the page.

Hope this is useful.

Please leave your comments.



Posted in MOSS 2007 | Tagged: , , , , , , , , , , | 8 Comments »

Form Web Part

Posted by Ramprasad Navaneethakrishnan on May 9, 2009

This post discusses about Form Web Part which is an out-of-the-box web part available with MOSS 2007.  Other out-of-the-box MOSS 2007 webparts are discussed here.

Form Web Part unlike other web parts does not operate alone. Usually this web part is used to provide input to other web parts / lists to act accordingly. For example,

  • Form web part can pass the url / path of an image that is to be displayed in the Picture web part.
  • Form web part can pass the value of the filter to be applied to a column in the sharepoint list.

Let us take one of the examples and discuss in detail.

There is a sharepoint list with the name ‘EmployeeDetails’ with the following columns. Name, Title, Email and Department.  The lists looks something like this


The requirement is, we want to dynamically apply the filter on the Department column. ie, we might want to see employees belonging to department ‘HR’ at one time and employees beloging to department ‘Sales’ another time.

For this, lets Add a Form Web Part to the page.

  1. Go to Site Actions –> Edit Page
  2. Click Add a Web Part
  3. Select Form Web Part from the list of web parts displayed
  4. By default, Form web part contains a  textbox and a ‘Go’ button.
  5. Variety of controls like Labels, check boxes etc can be added to the Form Web Part using the Source Editor present in the tool pane.( A web part’s tool pane can be accessed byclicking Modify Shared Web Part option present in the Edit menu of that web part). For simplicity, lets make use of the default controls available with the Form web part. Now the page looks something like this
  6. formwebpart
  7. Now in the Form Web Part, go to Edit –> Connections –> Provide values to –> Select ‘EmployeeDetails’.  This will open ‘Configure Connection’ dialog box.
  8. formwebpart-configureconnection
  9. Select Column T1 and click next (Note T1 is the name of the textbox in the form web part which you can see from the Source Editor of Form Web Part)
  10. Now a second dialog box appears that lists the columns present in the ‘EmployeeDetails’ list. Select the column for which we need to apply the filter. In our case it is ‘Deparment’ column
  11. formwebpart-configureconnection3
  12. Click Next or Finish to complete the configuration
  13. Now to list employee belonging to the department ‘HR’, enter ‘HR’ in the textbox of form web part and click Go. You can see the filtered EmployeeDetailas as below
  14. formwebpart-result1
  15. To get employees belong to Sales department, enter ‘Salee’ in the Form Web Part to get the needed list like below.
  16. formwebpart-result2


Hope this is useful..

Please leave your comments.


Posted in MOSS 2007 | Tagged: , , , , , | 11 Comments »

Sharepoint Webparts

Posted by Ramprasad Navaneethakrishnan on May 9, 2009

Web part is what that makes up the web pages in a sharepoint site. A Sharepoint site is nothing but a group of web pages in which each and every web page holds one or more web parts which in itself contains different types of data based on the type of the web part chosen. The following are the out-of-the-box web parts available with MOSS 2007.

  1. Content Editor Web Part
  2. Form Web Part
  3. Image Web Part
  4. List Web Part
  5. Page Viewer Web Part
  6. Site Users Web Part
  7. XML Web Part

Lets see each of these web parts in detail.

  • Content Editor Web Part
    • Content Editor Web Part is used to display data in the form of text, images, table and links. To provide input to this web part, it exposes three properties in its tool pane (A web part’s tool pane can be reached by Site Actions –> Edit Page –>Click Edit in the web part–>Select Modify Shared Web Part ). Those are
      • Source Editor : Data is entered in HTML format. The data can be formatted using HTML tags and it requires author to know the HTML syntax.
      • Rich Text Editor :  Allows to enter information in plain text. It provides tools to insert images, tables and links into the web part.
      • Content Link : This can be used to link this web part to a text file with HTML formatting.
  • Form Web Part
    • Form Web Part needed a separate post and it can be read here.
  • Image Web Part
    • This Web Part is used to add an image to your web part page. The image can be a drawing or a logo or a diagram. The supported image formats are .bmp, .emf, .gif, .jpg, .png
    • The path of the image can be given in the Image Link property in the web parts tool pane
  • Page Viewer Web Part
    • This web part displays the content of any web page that is linked to it. In addition to web pages, it can display the contents of a folder or a file for which the path is provided in the toolpane.
    • There will be three radio buttons in the toolpane for each for Web Page, Folders and Files. The appropriate radio button should be checked and in the Link textbox, the path of the webpage, file or folder should be provided.
  • Site Users Web Part
    • This web part displays the list of users and groups who have access to the Sharepoint site. There are three two filter conditions that can be applied to customize the users / groups being displayed.
      • Number Of Items To Display : Restricts the number of items (users / groups) being displayed in this web part. The value ranges from 1 to 1000.
      • Display Type:
        • Display Users / Groups who have direct permission.
        • Display user’s belonging to this Site’s members group
        • Display users from this group . ( The needed group name can be entered in the text box provided)
  • XML Web Part
    • This web part displays XML formatted data and applied XSL Transformtions prior to the display of the data.
    • XML Editor and XSL editor properties present in the tool pane allows the user to enter the XML data and XSL transformations.
    • XML Link and XSL Link properties present in the tool pane allows the user to link to XML files and XSLT files present anywhere in the connected network.

Hope this is useful.

There is also a post on out-of-the-box site templates in MOSS 2007 here.


Posted in MOSS 2007 | Tagged: , , , , , , , , , | 2 Comments »