Sharepoint Webpart Deployment

Initially when I first created a webpart for Sharepoint/WSS, I was kind of confused with the number of development and deployment options and kept on wondering for a while for the way to go. You can and should develop the webpart using Visual Studio but you have option to derive from Sharepoint webpart class or from .NET Webpart Class. You can deploy the webpart as a feature or you can deploy it using CAB file. Then you have .DWP and .Webpart files.

 

Sometime I even saw the message that not able to deploy the webpart since it doesn’t derive from Sharepoint Webpart class. I wondered, why is it that I am forced to derive from Sharepoint Webpart class when I don’t want to use any of the capabilities like inter-webpart communication etc etc.

I thought it would be helpful to jolt down some of my findings and post it here.

I already posted the comparison between deriving from Sharepoint Webpart class and .NET Webpart class. You can see it here

Now you have atleast 2 means to deploy the webpart…

1. Deployment using CAB files

2. Feature based deployment of a webpart

Deployment using CAB file, further vary a little when you are deriving from sharepoint webpart class or .net webpart class.

CAB based Deployment when deriving from Sharepoint Webpart Class

When you derive from Sharepoint Class, you should deploy create a DWP file like

 

<?xml version="1.0" encoding="utf-8"?>

<WebPart xmlns="https://schemas.microsoft.com/WebPart/v2" >

          <Title>Name of Webpart</Title>

          <Description>Webpart Description</Description>

          <Assembly>SampleAssemblyName, Version=1.0.0.0, Culture=neutral, PublicKeyToken=<public key token></Assembly>

          <TypeName>MyNamespace.WenpartClassName</TypeName>

          <!-- Specify default values for any additional base class or custom properties here. -->

</WebPart>

Save this file as <WebPartName>.dwp

One CAB project can be used to deploy one or more webparts. To guide the CAB project, you need manifest (With Name Manifest.xml) file. You create

Then, create a Manifest file, which guides the setup project about all dwp files, safe control entries and embedded resources etc etc..

Your manifest.xml may be something like..

<?xml version="1.0"?>

<WebPartManifest xmlns="https://schemas.microsoft.com/WebPart/v2/Manifest">

  <Assemblies>

    <Assembly FileName="WebpartAssemblyName.dll">

      <ClassResources>

  <ClassResource FileName="RelativeFile1.gif"/>

        <ClassResource FileName="RelativePathtoFile2.jpg"/>

      </ClassResources>

      <SafeControls>

        <SafeControl Namespace="YourNamespace" TypeName="*" />

      </SafeControls>

    </Assembly>

  </Assemblies>

  <DwpFiles>

    <DwpFile FileName="SampleDWP1.dwp"/>

    <DwpFile FileName="SampleDWP2.dwp"/>

  </DwpFiles>

</WebPartManifest>

Now you create a CAB project in Visual Studio and add Project Output of Webpart project to the CAB project. With that Manifest.xml will automatically be added. Next add DWP file and other resources as contents to CAB project.

CAB based Deployment when deriving from .NET Webpart Class

Here the process essentially remains the same, only the file content changes a little.

You create .Webpart file instead of .DWP and manifest changes a little.

Create a new file and name it as <WebpartName>.webpart. The content of file is as follows.

 

<?xml version="1.0" encoding="utf-8" ?>

<webParts>

          <webPart xmlns="https://schemas.microsoft.com/WebPart/v3">

                                  <metaData>

                                                          <type name="FullnamespaceandWebpartClassName, AssemblyName, Version=1.0.0.0, Culture=neutral, PublicKeyToken=<token>" />

                                                          <importErrorMessage>Cannot import this Web Part.</importErrorMessage>

                                  </metaData>

                                  <data>

                                                          <properties>

                                                                                  <property name="Title" type="string">Webpart title</property>

                                                                                  <property name="Description" type="string">Webpart Description</property>

                                                          </properties>

                                  </data>

          </webPart>

</webParts>

Create a new file manifest.xml with content as follows..

 

<?xml version="1.0"?>

<!-- You need only one manifest per CAB project for Web Part Deployment.-->

<!-- This manifest file can have multiple assembly nodes.-->

<WebPartManifest xmlns="https://schemas.microsoft.com/WebPart/v2/Manifest">

          <Assemblies>

                                  <Assembly FileName="WebpartAssemblyName.dll">

                                  <!-- Use the <ClassResource> tag to specify resources like image files or JScript files that your Web Parts use. -->

                                                          <!-- Note that you must use relative paths when specifying resource files. -->

                                                          <ClassResources />

                                                          <SafeControls>

                                                                                  <SafeControl Namespace="NameSpaceto be added as safecontrol in Sharepoint sites web.config." TypeName="*" />

                                                          </SafeControls>

                                  </Assembly>

          </Assemblies>

          <DwpFiles>

                                  <DwpFile FileName="WebpartFileName.webpart"/>

          </DwpFiles>

</WebPartManifest>

 

The creation of CAB project is essentially the same.

For both of these cases, you can deploy the webpart using following STSADM Commands.

 

stsadm -o deletewppack -name <WebpartCabName>.CAB

stsadm -o addwppack -filename <WebpartCabName.CAB > -globalinstall -url "https://<ServerName: PortNumber> " –force

Feature based Webpart Deployment

Here is a link to excellent post that steps to deploy webpart as a feature. Also you should see How Solution deployment has changed development with Sharepoint Technologies.

Comments