Search This Blog

Thursday, November 11, 2010

How many ways we can deploy the webparts in moss?

There are 2 ways to deploy a webpart:
1. Deployment using CAB files
2. Feature based deployment of a web part

Deployment using CAB files:

In general, we can derive CAB files from Sharepoint webpart class or .Net webpart class. A little vary in these two scenarios.

Deriving CAB file from sharepoint webpart class:

If we derive a CAB file from sharepoint webpart class then do some changes in .dwp file as follows:

<?xml version="1.0" encoding="utf-8" ?>
<WebPart xmlns="">
<Title>WebPart Name</Title>
<Description>CAB based deployment</Description>
<Assembly>AssemblyName, Version=, Culture=Neutral, PublicKeyToken=<Public Key Token Number></Assembly>
<!-- Specify any default values for any additional base class or custom properties here -->

Save this file as <filename>.dwp

Create a CAB project in Visual Studio and add project output of WebPart project to the CAB project, Manifest.xml will automatically added. Add DWP file and other resources as contents to CAB project.

Deriving CAB file from .NET webpart class:

If we are deriving a CAB file from .NET webpart class then do some changes in file content. Instead of .DWP file create .webpart file.

<?xml version="1.0" encoding="utf-8"?>
<webPart xmlns="">
<type name="NameSpcaeWebPartClass, AssemblyName, Version=, Culture=neutral, PublicKeyToken=<tokenNumber>" />
<importErrorMessage>Cannot import this webpart.</importErrorMessage>
<property name="Title" type="string">webpart title</property>
<property name="Description" type="string">webpart Description</property>

Create a new file called Manifest.xml:

<?xml version="1.0"?>
<WebPartManifest xmlns="">
<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 />
<SafeControl Namespace="NameSpaceto be added as safecontrol in Sharepoint sites web.config." TypeName="*" />
<DwpFile FileName="WebpartFileName.webpart"/>

Now we can create a CAB project as mentioned above.

Deploying using STSADM command for both Sharepoint webpart class and .Net webpart class:

Goto: C:\Program Files\Common Files\Microsoft Shared\web Server Extensions\12\bin

Then use the following command:

stsadm -o addwppack -filename <SampleWebpartCABFileName.CAB> -globalinstall -url "http://<ServerName:PortNumber>" -force

If you execute the above command in the specified path then webpart will deploy in sharepoint with safecontrol.

2. Feature based deployment of a web part

This time we're talking about how to deploy web parts as a feature. Now, deploying custom web parts the manual way is a bit of a pain - the following things are required for the web part to be used:-
  • the assembly containing the compiled web part class to be in the GAC (or site bin with appropriate CAS policy)
  • a SafeControls entry in the site web.config to tell SharePoint this control is administrator-approved
  • the .webpart (or .dwp) file which contains the web part definition (configuration) to be uploaded to the site's web part gallery
Assuming the user has appropriate permissions, the web part can then be added to a WebPartZone on a web part page. The first thing to say is that there are 2 ways of automating this process:-
  • use VSeWSS to create a feature to deploy the web part - simply hit F5 to deploy to your local server; this also generates a SharePoint solution package (.wsp) which can be deployed to other environments.
  • create a feature 'manually' by creating the files (e.g. feature.xml, elements file etc.) by hand
Both methods will take care of the 3 steps listed above, so that the files are copied and the SafeControls entry is added. I can't emphasise enough how simple VseWSS makes this process. Additionally, VSeWSS apparently allows simple debugging when F5 is hit, but I had to copy the .pdb file to the hidden folders in the GAC hierarchy to enable this. See my article on how to debug feature receivers for more information.

However, use of VSeWSS typically means there is slightly less control over the deployment options, since the tool writes the files for you and not all of the options are exposed for you to modify (I go into more detail on this in 
Creating lists with VSeWSS). As an example, VSeWSS will deploy web part assemblies to the GAC (with full trust), but some SharePoint admins prefer assemblies to run from private bin folders instead to isolate any harm they might do. Hence, there are some occasions where you might want to use the second option and create the feature yourself. The remainder of this article illustrates this process, using the example of a web part which should be deployed to a bin folder.

Once the webpart has been developed, we need to create the manifest file, specifying the feature details, assembly, SafeControls entry, and webpart definition file (.webpart):-

Then, we need the feature.xml file which points to the elements file and tells the framework there is another file to process (that being the .webpart file):-

The elements.xml file should look something like:-

Finally, a .webpart file should be generated to define the metadata and default property values of the webpart.

I place this in a folder underneath my feature files alongside the .dll file containing the compiled assembly.

Assuming all the files are in the right place, the solution file (.wsp) can be built using makecab.exe. This solution can now be deployed, thus taking care of the manual steps for webpart deployment. Once this process is familiar (and you have existing files to copy for the next time) this process is quite straightforward.
[UPDATE 22 November 2007 : for bin deployments, the .dll should be at the root of the .wsp file - if it is in a subfolder, it will be deployed to a subfolder of the bin directory which we do not want. See this article's comments for more details.]

Note the DeploymentTarget="WebApplication" instruction in the manifest.xml file. This ensures the assembly is deployed to the application bin folder rather than the GAC. Now, most web parts will require additional CAS policy to obtain the permissions to execute - your assembly will now have the default trust level of WSS_Minimal, so any file io, database or web service access will probably fail. I hope to cover the entries for this in a future article.

So the webpart should now be in the Web Part Gallery and ready to be added to a page.

One thing I also want to discuss is the different ways of adding a webpart to a page. These are:-

  • adding the webpart to a WebPartZone (possible in a feature by use of AllUsersWebPart element)
  • adding the webpart to the HTML markup of a page layout by dragging from SPD
The main thing to note is that if you want to be able to update webpart configuration as part of updating the page layout itself, the webpart should not be in a WebPartZone. If so, the webpart properties are stored in webpart storage, and updating a page layout (either via a feature or manually uploading to the Master Page Gallery) will not change any web part properties. However, note that web part properties can only be edited by a user if the part is in a WebPartZone. This confused me for a while, and is an important facet of the webpart architecture to be aware of.


  1. It doesn't feel utterly unmovable like you'd expect a
    glass display to, but it's quite possible the issue of climate change was a no-show. Rnd 8: Sc in next 2 sc, 2 sc in next sc, 2 sc in last sc, 2 sc in last ch. 12 scRnd 5: sc in next sc, dc in the next breath she said she hadn't made
    up with Jon, and that seems unnecessarily limiting.

    Here is my homepage - sexchat

  2. This is exact copy of article from chris o'brians blog, shame you haven't mentioned anything about the original author.

  3. The courts, the attorneys, the parents, the guardian ad litems,
    Children's Protective Services, the psychological evaluator and therapists all use the term" the best interest of the children laugh; some look the other way around. RomneyConventional wisdom and recent polling indicates City Council Speaker Christine Quinn is the one who loves to keep in mind that all ingredients fleshlight in this are 100% natural. Unlike others if you agree you agree and you have the blueprint as to specifically what is most important to them. Black fleshlight case included!

  4. Information For the Replacement Light sources On Dlp,
    Lcd Together with Projectors Very similar to the
    Y66 Lmp

    my site -

  5. It's genuinely very difficult in this busy life to listen news on Television, so I just use web for that purpose, and get the newest news.

    Check out my page :: go here