Click here to Skip to main content
14,452,924 members

Deploying a Custom WebPart to Sharepoint

Rate this:
4.54 (9 votes)
Please Sign up or sign in to vote.
4.54 (9 votes)
5 Mar 2009CPOL
Deploying a Custom WebPart to Sharepoint and using it in your site


In Part 1 of this article, I discussed how to create a custom Webpart which connects to database and pull data.

In this article (Part 2), I will show how to deploy the DatabaseConn Webpart that we have created to Sharepoint site and use it in any of your sites.

Deployment Methods

We can deploy a custom webpart in 2 ways:

  1. Deploying the Assembly (i.e. DatabaseConnWebpart.dll) to GAC
    This requires the assembly to be strong named, a change in manifest etc.
  2. Other simplest way is to deploy assembly to Sharepoint Virtual Directory folder in IIS, i.e. C:\inetpub\wwwroot\wss\VirtualDirectories\80\bin

Note: Sometimes using way 2 may create trust problems, so if you encounter that issue, try copying your DLL to GAC too. It will solve the issue.

Copying Assembly to Sharepoint BIN Folder

Sharepoint Virtual directory can be found at: C:\inetpub\wwwroot\wss\VirtualDirectories\80\bin.

Copy the DLL of DatabaseConnWebPart that we created from your project folder and paste it in the bin folder of portal directory and also GAC, c:\windows\assembly (if you encounter any trust issues).

Adding the Safe Control Entry

Even though the assembly is present in the Portal’s Bin folder, there is another step required to make the Control (Web Part) assembly usable on the Portal Pages.

Since the control will need to render on multiple machines in different browsers with as many user accounts as the organizations have, there is a need to declare the control as “safe”.

To do so, open the web.config file of Sharepoint portal placed under the portal’s directory, and look for <SafeControls> node in web.config and add the following Safe control code:

// Check for this node


// Add this line of code which ensures webpart is safe

<SafeControl Assembly="DatabaseConnWebPart " Namespace="DatabaseConnWebPart "

    TypeName="*" Safe="True" />


Now that we declared the webpart as safe, our webpart will be deployed to Sharepoint Portal.

Configuring Portal to Use NewWebPart

Open your Sharepoint portal and on your “Home”, click Site Actions -> Site Settings -> Modify all Site Settings as shown in this figure:


Sharepoint will open the Settings page.

Click “Webparts” under Galleries as shown below:


Adding Custom Webpart to Webparts Gallery

Click “New” in toolbar to add a new webpart as shown below:


Sharepoint will open the webparts gallery, choose your DatabaseConnWebPart from the gallery and check the checkbox to the left of webpart and click Populate Gallery on top as shown below.

Note: You can rename your webpart anyway you want. Use the TextBox provided to the right of your webpart to rename it accordingly.


Now we have successfully added our new custom web part to Sharepoint portal. We can go ahead and use that webpart in any site that we want.

Note : If you want to make sure whether your webpart is added to gallery or not, check the Webpart Gallery page. It should have your webpart.

Using DatabaseConnWebPart in Site

To use our new deployed webpart in a site, open the site and Click Site Actions -> Edit Page.

This will show the site in edit mode, now click "Add a WebPart" as shown below:


This will open the Add WebPart dialog box. Choose your webpart (in Miscellaneous section) and check it and click "Add" as shown below:


This will add the webpart to your home page and now your homepage as shown below:



This is how we can create custom webparts, deploy them to Sharepoint server and use them in our sites.

Happy programming!!!


  • 5th March, 2009: Initial post


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

Hithendra Reddy
Software Developer (Senior) Monster
United States United States
A .Net/Sharepoint Developer currently working with MONSTER in Boston, MA.

I like coding especially with C#,jquery, xml, xslt.

My hobbies include painting, poetry, photography and long drives.

Comments and Discussions

GeneralMisssing steps Pin
shatrunjay shukla20-Mar-12 10:04
professionalshatrunjay shukla20-Mar-12 10:04 
GeneralA error occured while previewing a webpart. Pin
patelsamir25210-Mar-11 7:09
Memberpatelsamir25210-Mar-11 7:09 
Generalsharepoint module problem Pin Pin
saiprakashsai19-Apr-10 21:43
Membersaiprakashsai19-Apr-10 21:43 
QuestionCustomize webpart for sharepoint Pin
serenadee20-Apr-09 20:50
Memberserenadee20-Apr-09 20:50 
GeneralDeploying a Custom WebPart to Sharepoint Pin
xusan19-Mar-09 5:30
Memberxusan19-Mar-09 5:30 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Posted 5 Mar 2009

Tagged as


32 bookmarked