ENTERPRISE

Microsoft Content Management Server Development : Building SharePoint Web Parts - Web Part Deployment

5/15/2013 1:43:30 AM

Web Parts are compiled as .NET assemblies and can be reused many times in Windows SharePoint Services and SharePoint Portal Server. Web Parts are usually deployed using cabinet (.CAB) files. We will create a cabinet file project in Visual Studio .NET that will encapsulate the assemblies and metadata for our Web Part. This cabinet file must then be installed using the stsadm.exe utility that comes with WSS/SPS. To deploy the Web Part we will perform the following steps:

1.
Prepare the Web Part Description

2.
Prepare the Web Part Manifest

3.
Create a CAB file deployment project

4.
Execute the deployment

Another installation tool for packaging and deploying Web Parts, called WPPackager, is available at http://www.microsoft.com/downloads/details.aspx?familyid=0fda5912-c136-4b44-911a-011adfcc66e3&displaylang=en. WPPackager creates a Windows Installer File (.MSI) for your Web Part, which performs the necessary configuration of SPS/WSS during installation.

For more information on this tool, see Using WPPackager to Package and Deploy Web Parts for Microsoft SharePoint Products and Technologies at http://msdn.microsoft.com/library/default.asp?url=/library/en-us/odc_SP2003_ta/html/sharepoint_deployingwebparts_msi.asp.


Preparing the Web Part Description (.DWP) File

When deploying a Web Part to SharePoint, several files should be populated during the deployment process. One of these files is the Web Part Description (.DWP) file.

1.
In Visual Studio .NET, right-click on the ExtensibleMCMSPageListingWebPart project and choose Add New Item.

2.
In the Categories pane on the left, expand Local Project Items and select Data.

3.
Select Web Part DWP.

4.
Enter the name as NavigationWebPart and click OK.

The .DWP file describes our Web Part, giving the default values for properties and any assemblies that the Web Part requires. Let’s create this file for our navigation Web Part:

<?xml version="1.0" encoding="utf-8"?>
<WebPart xmlns="http://schemas.microsoft.com/WebPart/v2" >
  <Title>Extensible MCMS Page Listing Web Part</Title>
  <Description>
    Displays MCMS Postings and Channels within a specified channel and
    transforms the display using XSLT.
  </Description>
  <Assembly>ExtensibleMCMSPageListingWebPart</Assembly>
  <TypeName>ExtensibleMCMSPageListingWebPart.NavigationWebPart</TypeName>
</WebPart>

The values specified in this file allow Windows SharePoint Services to generate metadata for the Web Part. The meanings of the elements are given in the table below:

Element NameDescription
TitleTitle that the user will see in the Web Part Library and the default title of the Web Part once it is added in a Web Part Zone.
DescriptionTooltip that will appear over the Web Part title in the Web Part library.
AssemblyAssembly name. For this sample we are only using the assembly name but it is also possible to use the complete Web Part assembly description like so: AssemblyName (without the .DLL extension), Version=VersionNumber, Culture=Culture, PublicKeyToken=PublicKeyToken
TypeNameThe namespace-qualified class name.

Preparing the Web Part Manifest File

When deploying a Web Part as a CAB file, we must create a Web Part manifest file that gives the CAB file deployment project the details of our Web Part and our Web Part description files.

1.
In Visual Studio. NET, right-click on the ExtensibleMCMSPageListingWebPart project and choose ‘Add New Item’.

2.
In the Categories pane on the left, expand Local Project Items and select Data.

3.
Select WPManifest.

4.
Enter the name as Manifest and click Open.

Enter the following code for this file to correspond to our Web Part:

<?xml version="1.0"?>
<WebPartManifest xmlns="http://schemas.microsoft.com/WebPart/v2/Manifest">
  <Assemblies>
    <Assembly FileName="ExtensibleMCMSPageListingWebPart.dll">
      <ClassResources>
        <ClassResource FileName="TestXml.xml"/>
        <ClassResource FileName="DefaultXsl.xslt"/>
      </ClassResources>
      <SafeControls>
        <SafeControl Namespace="ExtensibleMCMSPageListingWebPart"
                      TypeName="*" />
      </SafeControls>
    </Assembly>
  </Assemblies>
  <DwpFiles>
    <DwpFile FileName="NavigationWebPart.dwp"/>
  </DwpFiles>
</WebPartManifest>

Manifest.xml allows us to include multiple assemblies, resources, and Web Part description files in our deployment CAB file. The elements are explained below:

Element NameDescription
AssembliesAllows us to include multiple assemblies in our cabinet file.
AssemblyUsed to define an assembly by setting the FileName attribute to the DLL name.
ClassResourcesDefines the resources used by our classes. The paths to the resources must be relative to the project files. Resources are supporting files such as images or data files.
SafeControlsLists the safe controls that will be used by this Web Part (so they can be added to the Web.config of the SharePoint site on deployment).
DwpFilesUsed to define the Web Part Description files used by this Web Part.

Creating the Deployment Project

At this point, we have a completed Web Part project with the necessary deployment configuration files. Now we need to create a deployment project to encapsulate the Web Part and other necessary files into a single cabinet file for installation.

1.
In Visual Studio .NET, right-click on the ExtensibleMCMSPageListingWebPart solution and choose ‘Add New Project’.

2.
In the Project Types pane, select Setup and Deployment Projects and in the templates pane, select Cab Project.

3.
Enter the name ExtensibleMCMSPageListingWebPartDeployment and click OK.

4.
Right-click on the ExtensibleMCMSPageListingWebPartDeployment project and select Add and then Project Output.

5.
Select ExtensibleMCMSPageListingWebPart from the project drop-down list.

6.
Holding down the Ctrl key, select Primary Output and Content Files and click OK.

7.
In the ExtensibleMCMSPageListingWebPart project, right-click on NavigationWebPart.dwp and click Properties.

8.
Set the Build Action attribute to Content. This will allow the deployment project to add the file to the package.

Your deployment project should now look like this:

Now build your deployment project by right-clicking on the project and selecting Build.

Executing the Deployment

Now that we have our cabinet file, let’s deploy it to our SharePoint server.

If you are developing on a remote workstation, copy the cabinet file to your server before following the steps below.


We will deploy it using stsadm.exe, which you will find under <local_drive>\Program Files\ Common Files\Microsoft Shared\Web Server Extensions\60\bin\.

Start a DOS command prompt, and enter the following commands:

cd "C:\Program Files\Common Files\Microsoft Shared\web server extensions\60\BIN\"

STSADM.EXE -o addwppack -filename "C:\Documents and Settings\Administrator\
My Documents\Visual Studio Projects\ExtensibleMCMSPageListingWebPartDeployment\
Debug\ExtensibleMCMSPageListingWebPartDeployment.cab" -globalinstall -force

					  

The Path C:\Documents and Settings\Administrator\My Documents\Visual Studio Projects\ may need to change depending on where you have created the project.


If the Web Part was successfully deployed, you should see:

ExtensibleMCMSPageListingWebPartDeployment.cab: Deploying to http://server/.
Operation completed successfully.

					  

When you compile the deployment project in Release mode, the command line will change to:

STSADM.EXE -o addwppack -filename C:\Documents and Settings\Administrator
\My Documents\Visual Studio Projects\ExtensibleMCMSPageListingWebPartDepl
oyment\Release\ExtensibleMCMSPageListingWebPartDeployment.cab" -globalins
tall -force


Here’s what happens when this command is executed:

  • A copy of our Web Part assembly is placed in the bin directory of the SharePoint site.

  • The Web Part is added to the SafeControls element of the SharePoint site’s Web.config.

  • A copy of the CAB file is added to the SharePoint configuration database.

  • Resources used by the assembly are copied into the Wpresources directory for the site. This directory can be found at c:\inetpub\wwwroot\wpresources\.

  • The .dwp files are copied into the wpcatalog directory of the site. This directory can be found at c:\inetpub\wwwroot\wpresources\.

As we are not installing our Web Part into the GAC or specifying a Code Access Security Policy, we need to increase the trust level of the SharePoint site to Full by following these steps:

1.
Open the SharePoint site’s Web.config (typically c:\inetpub\wwwroot\Web.config).

2.
Update the trust element’s level attribute to Full.

3.
Save Web.config.

There are a lot of security considerations when writing Web Parts such as: Trust Levels, whether or not to put the Assembly in the GAC, and Code Access Security. For more information, see http://msdn.microsoft.com/library/default.asp?url=/library/en-us/odc_sp2003_ta/html/sharepoint_wsscodeaccesssecurity.asp.


Right-Click Deployment of Web Part CAB Files

If you are frequently redeploying Web Parts to your server, running stsadm.exe can be a laborious task. To simplify this, we can create a batch file and a type mapping that will let us right-click on the Web Part to install it.

To do this:

1.
Create a batch file called C:\Program Files\Common Files\Microsoft Shared\web server extensions\60\BIN\deploy_webparts.bat.

2.
Edit the batch file and enter the following:

STSADM.EXE -o addwppack -filename %1 -globalinstall -force
pause

3.
Save and close the batch file

4.
Now, open Windows Explorer and choose Tools | Folder Options | File Types from the menu.

5.
If no entry exists for CAB files, click New and enter CAB.

6.
Select the entry for CAB files and click Advanced.

7.
Select New and enter an action name of Install Web Part.

8.
Under Application Used to Perform action, enter C:\Program Files\Common Files\ Microsoft Shared\web server extensions\60\BIN\deploy_webparts.bat.

9.
Click OK, OK again, and then click Close.

10.
Browse to C:\Documents and Settings\Administrator\My Documents\Visual Studio Projects\ExtensibleMCMSPageListingWebPartDeployment\Debug\, right-click on ExtensibleMCMSPageListingWebPartDeployment.cab and choose Install Web Part to deploy your Web Part.

Other  
 
Video tutorials
- How To Install Windows 8 On VMware Workstation 9

- How To Install Windows 8

- How To Install Windows Server 2012

- How To Disable Windows 8 Metro UI

- How To Change Account Picture In Windows 8

- How To Unlock Administrator Account in Windows 8

- How To Restart, Log Off And Shutdown Windows 8

- How To Login To Skype Using A Microsoft Account

- How To Enable Aero Glass Effect In Windows 8

- How To Disable Windows Update in Windows 8

- How To Disable Windows 8 Metro UI

- How To Add Widgets To Windows 8 Lock Screen
programming4us programming4us
Top 10
Free Mobile And Desktop Apps For Accessing Restricted Websites
MASERATI QUATTROPORTE; DIESEL : Lure of Italian limos
TOYOTA CAMRY 2; 2.5 : Camry now more comely
KIA SORENTO 2.2CRDi : Fuel-sipping slugger
How To Setup, Password Protect & Encrypt Wireless Internet Connection
Emulate And Run iPad Apps On Windows, Mac OS X & Linux With iPadian
Backup & Restore Game Progress From Any Game With SaveGameProgress
Generate A Facebook Timeline Cover Using A Free App
New App for Women ‘Remix’ Offers Fashion Advice & Style Tips
SG50 Ferrari F12berlinetta : Prancing Horse for Lion City's 50th
Popular Tags
Video Tutorail Microsoft Access Microsoft Excel Microsoft OneNote Microsoft PowerPoint Microsoft Project Microsoft Visio Microsoft Word Active Directory Exchange Server Sharepoint Sql Server Windows Server 2008 Windows Server 2012 Windows 7 Windows 8 Adobe Flash Professional Dreamweaver Adobe Illustrator Adobe Photoshop CorelDRAW X5 CorelDraw 10 windows Phone 7 windows Phone 8 Iphone