Search This Blog

Friday, October 22, 2010

Web part Deployment Guide

Step By Step Web Part Deployment Guide



Following deployment of sharepoint webpart applied to
WSS 3.0/MOSS 2007 using MS Visual Studio 2008

Web Part Dployment Steps:

Step 1: File-New-Project-C#-Class Library Project

Step 2: Add Reference
right click on project and click on “addreference”.
Add “System.web” from “.Net” tab.

Add another reference named “Microsoft.Sharepoint” by browsing from “C:\Program Files\Reference Assemblies\Microsoft\Framework\v3.5” directory

(copy “Microsoft.sharepoint.dll” file into “C:\Program Files\Reference Assemblies\Microsoft\Framework\v3.5” directory to use it.)

Step 3: Class file coding:

add following reference into the class file:

using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Microsoft.SharePoint.WebPartPages;

Inherit class from “Webpart” class:

public class Class1 : WebPart

Complete class fie code is as follows:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Microsoft.SharePoint.WebPartPages;

namespace wp2
{
public class Class1 : WebPart
{
protected override void RenderContents(HtmlTextWriter writer)
{
writer.Write(“Hi ” + this.Context.User.Identity.Name);
}
}
}

Step 4: To set the version number and allow partially trusted callers

1.    In Solution Explorer, double-click the AssemblyInfo file
2.    Edit the line:

C#
[assembly: AssemblyVersion(“1.0.*”)]

Visual Basic

so that it reads:

C#
[assembly: AssemblyVersion(“1.0.0.0”)]

Visual Basic

3.    Add the following line to the top of the file:

C#
using System.Security;

Visual Basic
Imports System.Security;

4.    Add the following line to the bottom of the file:

C#
[assembly: AllowPartiallyTrustedCallers]

Visual Basic

Project file Property settings:

Now right click on project file and click on “properties”.
Now go into the “build” tab and set “output path” as the server’s sharepoint bin directory like “\\[sharepoint path with port]\Inetpub\wwwroot\wss\VirtualDirectories\dbvss80\bin\”
(this will create dll of this project into the output directory)

Web Config Settings:

add the following code into SharePoint web config file:
(Webconfig is into the “\\[sharepoint path with port]\Inetpub\wwwroot\wss\VirtualDirectories\dbvss80” directory)
add “” between “” section.

Use of Web Part into SharePoint Site :

Click on “Site Action”->”Site Settings”-> go to “Galleries” section and click on “Web Parts”

Now you can see the web part list on page. To add new web part click on “New” link on top.

Now you can see the all “safe web parts” in list selected related webpart from list and click button “Populate Gallery” from top.

Now you are ready to use Web part…

just edit page and click on “Add webpart section” and select related web part from list. (most of new web parts are under the “miscellaneous” section.)

Enjoy Web part development.

5 comments:

  1. even after deployment when I click on the webpart I am getting error as "webpart cannot be displayed or imported.the type is not registered safe "
    But I have registerd it as safe

    ReplyDelete
  2. Add the Safe Control in Web.config file properly

    ReplyDelete
  3. SafeControl Assembly="SimpleWebPart, Version=1.0.0.0, Culture=neutral, PublicKeyToken=################" Namespace="MyWebParts" TypeName="*" Safe="True"

    ReplyDelete
  4. We absolutely love your blog and find many of your post's to be exactly what I'm looking
    for. Do you offer guest writers to write content in your case?
    I wouldn't mind publishing a post or elaborating on a few of the subjects you write regarding here. Again, awesome website!
    Also see my website :: safe diets

    ReplyDelete