Dotnetdreamer's Weblog

SharePoint, Silverlight and Azure

Posts Tagged ‘IISRESET’

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 »

Access Denied – Activating Microsoft Office Server Publishing Infrastructure

Posted by Ramprasad Navaneethakrishnan on April 27, 2009

Hi Fellas,

Stuck up with the error “Access Denied” while activating the Publishing Infrastructure feature?? Read this post for solution

I was trying to create a sharepoint site with the Report Center template under the Enterprise tab.


I got the message that I need to activate Publishing Infrastruture Feature in Site Collection before creating site of this type.


I went to Site Collection Features in the section Site Collection Administration through Site Actions – > Site Settings


When tried to activate the Publishing Infrastructure Feature, I got the Access Denied error.


Solution 1:

Run the following command

stsadm -o activatefeature -name PublishingResources -url <siteurl>

Solution 2:

After some analysis, I found out that the AppPool for the current web application is having limited privileges. I did the following steps to resolve the problem

1. Open IIS. Locate the Web Applications. Go to properties. Select the Home Directory tab. Change the Application Pool to the one used by the Central Administration


3. Go the Site Collection Features. Activate the feature. Now it gets activated!

4. Go to IIS. Change the Application pool of the web application to the original one.


6. Now go back and create the Report Cente Site

Hope this will be useful. Forgive me for the horrible screenshots 🙂



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