Thursday, May 28, 2009

Deploying web parts in MOSS 2007

Web parts play vital role when it comes to user interface in share point technologies. The steps to create and deploy the web part are as follows:

Creating Web Part Solution

1) Open Visual Studio 2005 and create a new project. Select the project template as Web Part.


2) In my case, I am naming the solution as MySampleWebPart. The cs file and the Solution Explorer would look something like this: 

3)  Add few controls and render the same. The sample code would look like: 

 

4) To this project add a xml file and name it as manifest.xml. The contents of this file should look like:

The Deployment Target attribute can be WebApplication/GlobalAssemblyCache based on the requirement.

The safe control entry would be required for the web part to be registered safe. It would contain the namespace and assembly details. You can find them in Project properties. 

5) Build the solution and ensure that you do not get build errors.

6) Now, we need to create a CAB project for deploying the solution. For this, click on the solution name, Select Add -> New Project. This would open a pop up window with the project types. Select the project template as CAB Project

In my case, I am naming the CAB project as MySampleCodeSetUp. 

7) Right click on the CAB project (MySampleCodeSetUp), Select Add-> Project Output. This would give a pop-up window for selecting the project output group. Select Primary Output and Content Files. Click OK.

8) Now, build the solution once again. Ensure that there are no build errors. The successful build would create the file MySampleCodeSetUp.cab which would contain all necessary files for web part deployment.

Deploying the web part solution

 1)      Open the command prompt and type the command cd  C:\Program Files\Common Files\Microsoft Shared\web server extensions\12\BIN

2)      Run the stsadm utility to add the solution. The command for adding the solution is: stsadm -o addsolution -filename MySampleCodeSetUp.cab. If the solution was added successfully, you would get the message, Operation was completed successfully. You can verify the same in Central Administration-> Operation-> Solution Management. Here you can find the newly added solution.

3)      Now, we need to deploy the solution. You can do it manually in the Central Administration or use the stsadm utility. The stsadm command for deploying the solution is: stsadm -o deploysolution -name MySampleCodeSetUp.cab –url http://servername (url of the share point site)

4)      You can find the dll for the web part at C:\Inetpub\wwwroot\wss\VirtualDirectories\\bin 

Populate the web part gallery

1)      Open the sharepoint site (top level site) . Site Actions->Site Settings-> Modify All Site Settings.

2)      Under Gallery you can find Web Parts.

3) Click New and select the new web part which was newly added. Click the button Populate Gallery on the top.


4) Open the share point site. Go to Site Action-> Edit Page. Click on Add Web Part . This would populate all the web parts which can be added. Here , we can find the newly added web part. Select the web part MySampleCode and Click Ok.



No comments: