Export (0) Print
Expand All
Add a Recycle Bin to Windows SharePoint Services for Easy Document Recovery
Use Windows SharePoint Services as a Platform for Building Collaborative Applications
Use Windows SharePoint Services as a Platform for Building Collaborative Apps, Part 2
Expand Minimize

Packaging and Deploying Web Parts for Microsoft Windows SharePoint Services

 

Suraj Poozhiyil and Jeremy Martin
Microsoft Corporation

May 2003

Applies to:
    Microsoft® Windows® SharePoint™ Services
    Microsoft Office SharePoint Portal Server 2003
    Microsoft Visual Studio® .NET
    Web Part infrastructure

Summary: Learn how to package and deploy Web Parts by using the administration tools provided with Microsoft Windows SharePoint Services. (12 printed pages)

Note   The information in this article also applies to Microsoft Office SharePoint Portal Server 2003, which is built on the Windows SharePoint Services platform.

Contents

Introduction
Building a Web Part Package
Deploying a Web Part Package
Adding a Web Part Package
Deleting a Web Part Package
Enumerating a Web Part Package
Switches
Installing a Web Part Package
Conclusion

Introduction

Web Parts are more than just the assemblies into which they are compiled. A Web Part may have class resources such as images, Microsoft JScript® files, and Help files. These files may also be localized and deployed in locations that are different from the location of the Web Part. Additionally, the Web Part must be added to the SafeControl list for the specific virtual server before users can take advantage of its functionality.

Prerequisites

  • Familiarity with Microsoft Windows® SharePoint™ Services and/or Microsoft Office SharePoint Portal Server 2003
  • Knowledge about how to create a Web Part
  • Familiarity with the Web Part infrastructure

Building a Web Part Package

A Web Part package is a cabinet (.cab) file that contains the following items:

  1. Manifest.xml (mandatory)
  2. Web Part assemblies (optional)
  3. Class resource files (optional)
  4. .dwp files (optional)

Creating a Manifest File for a .cab File

The Manifest file, a configuration file that describes the structure and contents of the .cab file, is the only required component for the .cab file. The Stsadm.exe tool uses this file to deploy the remaining content of the .cab file.

The following table describes the nodes and subnodes in the Manifest.xml file.

NodeParent NodeDescription
WebPartManifestWebPartManifestDefines the schema of the XML.
AssembliesWebPartManifestContains definitions for each of the assemblies being deployed.
AssemblyAssembliesUses the FileName attribute to define the assembly file name, contains the definitions for the class resources, and contains the XML for the SafeControls list.
ClassResourcesAssemblyContains the definitions for each class resource being deployed.
ClassResourceClassResourcesUses the FileName attribute to define the class resource file name.
SafeControlsAssemblyContains the definitions for each line of XML in the SafeControls list.
SafeControlSafeControlsDefines each line of the SafeControls list.
DwpFilesWebPartManifestContains definitions of each .dwp file being deployed.
DwpFileDwpFilesUses the FileName attribute to define the file name of the .dwp file.

The following example shows a manifest file for a package that deploys two assemblies and their resources:

<?xml version="1.0" encoding="utf-8" ?> 
<WebPartManifest xmlns="http://schemas.microsoft.com/WebPart/v2/Manifest">
   <Assemblies>
      <Assembly FileName="WebPartLibrary1.dll">
         <ClassResources>
            <ClassResource FileName="image1.gif"/>
            <ClassResource FileName="image2.gif"/>
         </ClassResources>
         <SafeControls>
            <SafeControl Namespace="WebPartLibrary1" TypeName="*"/>
         </SafeControls>   
      </Assembly>
      <Assembly FileName="WebPartLibrary2.dll">
         <ClassResources>
            <ClassResource FileName="MyCustomHelp.htm"/>
            <ClassResource FileName="LargeIcon.gif"/>
         </ClassResources>
         <SafeControls>
            <SafeControl Namespace="WebPartLibrary2" TypeName="*"/>
         </SafeControls>   
      </Assembly>
   </Assemblies>      
   <DwpFiles>
      <DwpFile FileName="WebPart1.dwp"/>
      <DwpFile FileName="WebPart2.dwp"/>
   </DwpFiles>
</WebPartManifest>

Creating a .cab File

Developers can use either of the following methods to create a .cab file:

  • Use Microsoft Visual Studio® .NET Professional to create a CAB Project.
  • Use MakeCAB.exe, a command-line tool included with Microsoft Windows 2000 and later.

Using Visual Studio

To use Visual Studio.NET Professional to create a CAB project, follow these steps:

  1. Start Visual Studio .NET.
  2. Create a new solution.
    • On the File menu, point to New, and then click Blank Solution.
    • Type a name for the solution, and then click OK.
  3. Open the Web Part project within this solution.
    • In Solution Explorer, right-click the new solution, point to Add, and then click Existing Project.
    • Browse to the location of Web Part project that you want to add, click the project, and then click Open.
  4. Create a new CAB project
    • In Solution Explorer, right-click the new solution, point to Add, and then click New Project.
  5. Under Project Types, click Setup and Deployment Projects, and then under Templates, click Cab Project.
    • Type a name for the CAB project, and then click OK.
  6. Add the Web Part project output to the CAB project.
    • In Solution Explorer, right-click the CAB project, point to Add, and then click Project Output.
    • In the Project box, click the Web Part project that you added to the solution in step 3.
    • Select all the appropriate file categories that appear in the list, and then click OK.

    Make sure that you select Primary output and Content Files. These categories add the Manifest.xml file, the .dwp files, and the Web Part assembly to the .cab file. Verify that the Manifest.xml file and the .dwp files are marked as content for build action in their respective properties sheets.

  7. Build the solution to create the .cab file.

Using MakeCAB.exe

MakeCAB.exe is a tool included with Windows 2000 or later. To use MakeCAB.exe to create a .cab file, follow these steps:

  1. Create a directive file for makecab.exe, and save the file with a .ddf extension. The following sample directive file (named sample.ddf) creates a .cab file for a simple Web Part library project:
    ;*** Sample Source Code MakeCAB Directive file example
    ;
    .OPTION EXPLICIT     ; Generate errors 
    .Set CabinetNameTemplate=SampleCab.cab       
    .set DiskDirectoryTemplate=CDROM ; All cabinets go in a single 
      directory
    .Set CompressionType=MSZIP;** All files are compressed in cabinet files
    .Set UniqueFiles="OFF"
    .Set Cabinet=on
    .Set DiskDirectory1=SAMPLECAB.CAB
    manifest.xml
    WebPart1.dwp
    WebPartLibrary1.dll
    ;*** <the end>
    
    
  2. Copy all the files that you want to include in the .cab file into the directory where you created the .ddf file. In this example, these files are the Manifest.xml file, the WebPart1.dwp file, and the WebPartLibrary1.dll file.
  3. Open a command prompt, change to the directory that contains the .ddf file and the files that you want to include in the .cab file, and then run the following command:
    Makecab.exe /F sample.ddf
    
    

MakeCAB.exe creates a directory named SAMPLECAB.CAB, and in this directory MakeCAB.exe creates a .cab file named SampleCab.cab that contains the three files listed in the Sample.ddf directive file.

For more information about MakeCAB.exe, download the Microsoft Cabinet Software Development Kit.

Creating a CAB File with Localized Resources

Visual Studio does not support creating .cab files with internal directories. However, localized Web Parts may require a .cab file with internal directories. Because of this you must use a tool like MakeCAB.exe or another, third-party CAB utility to deploy localized Web Parts.

The following example describes how to create a .cab file for an English language Web Part project named SampleWebPartLibrary that also provides German localized resources. The .cab file in this example is named Sample.cab, and it must include the following files:

  • SampleWebPartLibrary.dll
  • Help.htm
  • Image1.gif
  • WebPart1.dwp
  • de-DE/Help.htm
  • de-DE/Image1.gif
  • de-DE/WebPart1.dwp

To create the .cab file for this example Web Part project, follow these steps:

  1. Create the appropriate Manifest.xml file. The following example shows the Manifest.xml file for the Sample.cab file:
    <?xml version="1.0" encoding="utf-8" ?> 
    <WebPartManifest 
      xmlns="http://schemas.microsoft.com/WebPart/v2/Manifest">
       <Assemblies>
          <Assembly FileName="SampleWebPartLibrary.dll">
             <ClassResources>
                <ClassResource FileName="image1.gif"/>
                <ClassResource FileName="help.htm"/>
                <ClassResource FileName="de-DE\image1.gif"/>
                <ClassResource FileName="de-DE\help.htm"/>
             </ClassResources>
             <SafeControls>
                <SafeControl Namespace="SampleWebPartLibrary" 
                  TypeName="*"/>
             </SafeControls>
          </Assembly>
       </Assemblies>      
       <DwpFiles>
          <DwpFile FileName="WebPart1.dwp"/>
          <DwpFile FileName="de-DE\WebPart1.dwp"/>
       </DwpFiles>
    </WebPartManifest>
    
    
  2. Create the appropriate Makecab.exe directive file. The following example shows the directive file for the Sample.cab file:
    ;*** Sample Source Code MakeCAB Directive file example
    ;
    .OPTION EXPLICIT ; Generate errors 
    .Set CabinetNameTemplate=Sample.cab    
    .set DiskDirectoryTemplate=CDROM ; All cabinets go in a single 
      directory
    .Set CompressionType=MSZIP ;** All files are compressed in cabinet 
      files
    .Set UniqueFiles="OFF"
    .Set Cabinet=on
    .Set DiskDirectory1=SAMPLE.CAB
    manifest.xml
    WebPart1.dwp
    SampleWebPartLibrary.dll
    Image1.gif
    help.htm
    .Set DestinationDir=de-DE
    de-DE\WebPart1.dwp
    de-DE\image1.gif
    de-DE\help.htm
    ;*** <the end>
    
    
  3. Copy all the files that you want to include in the .cab file into the directory where you created the .ddf file, and copy all of the localized resources into the appropriate subdirectories. The following example shows the directory structure for the Sample.cab file:
    \Directory with directive file
                  Sample.ddf
                  Manifest.xml
                  SampleWebPartLibrary.dll
                  WebPart1.dwp
                  Image1.gif
                  Help.htm
                  \de-DE
                            WebPart1.dwp
                            Image1.gif
                            Help.htm
    
    
  4. Open a command prompt, change to the directory that contains the .ddf file and the files that you want to include in the .cab file, and then run the following command to create a subdirectory in the Sample.cab file and prepare the Sample.cab file for deployment:
    Makecab.exe /F sample.ddf
    
    

Deploying a Web Part Package

Administrators can use the Stsadm.exe tool to deploy .cab files created by developers. Stsadm.exe is a command-line tool that you can use to manage a Windows SharePoint Services computer. Three Stsadm.exe options apply to Web Part package deployment:

  • AddWPPack
  • DeleteWPPack
  • EnumWPPacks

For more information about a specific Stsadm.exe command-line option, type the following line at a command prompt:

stsadm –help option

Adding a Web Part Package

To use the Stsadm.exe command to deploy a Web Part package on a server computer running Windows SharePoint Services, open a command prompt, and then type the following command:

stsadm.exe -o addwppack 
-filename Web_Part_Pack_name
[-url URL]
[-globalinstall]
[-force]

If you want to install a Web Part package on a virtual server when the Web Part package is already installed on another virtual server on the same computer, use the following command:

stsadm.exe -o addwppack
-name Web_Part_Pack_name
[-url URL]
[-globalinstall]
[-force]

Switches

The following table describes Stsadm.exe command-line switches that support adding Web Part packages.

SwitchDescription
-url
Specifies the URL of the virtual server on which you want to install the Web Part package.
Note   If you do not use this switch, then the package is installed on all Windows SharePoint Services-enabled virtual servers on the computer.
-name
Installs a Web Part package to a virtual server from the Configuration database. When the package is installed on the computer for the first time, Stsadm.exe makes a copy of the .cab file in the Configuration database. In a server farm deployment, after the administrator installs a Web Part package on the front-end Web server, you can install the Web Part package on all front-end Web servers without a local copy of the .cab file.
-globalinstall
Installs the Web Part package to the global assembly cache (GAC). Only strong-named Web Part assemblies in the Web Part package are installed to the GAC; all other assemblies are installed in the Bin directory of the virtual server.
-force
Forces Stsadm.exe to overwrite an installed Web Part package. If the Web Part package specified on the command line already exists on the server, you can use this switch to overwrite that package.
-filename 
Forces Stsadm.exe to use the .cab file specified by the path on the command line.

Deleting a Web Part Package

To delete a Web Part package from specified virtual servers on a computer running Windows SharePoint Services, open a command prompt, and then type the following command:

stsadm.exe -o deletewppack
           -name Web_Part_Pack_name
           [-url URL]

Switches

The following table describes Stsadm.exe command-line switches that support deleting Web Part packages.

SwitchDescription
-name
Used to specify the Web Part package to delete.
-url
Specifies the URL of the virtual server that contains the Web Part package that you want to delete.
Note   If you do not use this switch, then the package is deleted from all Windows SharePoint Services-enabled virtual servers on the computer.

Enumerating a Web Part Package

To list all the Web Part packages installed on a computer running Windows SharePoint Services, open a command prompt, and then type the following command:

stsadm.exe -o enumwppacks
           [-name Web_Part_Pack_name]
           [-url URL]
           [-farm]

Switches

The following table describes Stsadm.exe command-line switches that support enumerating Web Part packages.

SwitchDescription
-name
Determines if the specified Web Part package is installed.
-url
Specifies the URL of the virtual server that contains the Web Part packages that you want to enumerate. If you do no use this switch, then the list includes all packages that are installed on all Windows SharePoint Services-enabled virtual servers on the computer.
-farm
Enumerates all the Web Part packages that are installed on a server farm deployment of Windows SharePoint Services.

Installing a Web Part Package

To decide whether to install a Web Part package in the GAC or in the Bin directory, ask the following questions:

  • Do you want to make this package available to all virtual servers on your computer?
  • Do you trust the assemblies and resources of the package completely?

If you answer "yes" to both of these questions, install the Web Part package to the GAC. Assemblies in the GAC are fully trusted and are available to all virtual servers.

The following table lists the differences between installing to the GAC and installing to the Bin directory.

ItemGACBin directory
Assembly locationlocal_drive:\Windows\Assemblylocal_drive:\virtual_server_file system_location\bin
Class resourceslocal_drive:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\wpresources

URL: http://virtual_server/_wpresources

local_drive:\ virtual_server_file system_location\wpresources

URL: http://virtual_server/wpresources

Default Security Trust LevelFullPartial (WSS_Minimal)
Accessible by all Virtual ServersYes (The assemblies and types must be enabled in the SafeControls list for each virtual server)No (The Web Part package is only accessible from the virtual server on which the assembly is installed.)
Pre-requisites for using Stsadm.exeThe assembly must be a strong-named assembly. 
Requires using the -globalinstall switch.YesNo
Note   If you install the assembly to the Bin directory and the assembly requires code access security permissions that exceed the default policy for the Bin directory, you can assign these permissions after the deployment is complete. For information about code access security, see the Microsoft Windows SharePoint Services 2.0 Software Development Kit (SDK) available from the Microsoft SharePoint Products and Technologies Developer Center.

Conclusion

You can use Stsadm.exe to deploy Web Part packages to the GAC or to the Bin directory for specified virtual servers. This allows you to deploy Web Part packages across an entire organization or only to a limited set of sites according to your requirements.

Show:
© 2014 Microsoft