Deploying a WebPart in SharePoint 2007

This is one of those topics, which I frequently look up, and so what better place to put the information than this blog?  Scot Hillier has explicit instructions in his book (Microsoft SharePoint – Building Office 2007 Solutions in C#) on page 404 to deploy a webpart using a solution package.  The following instructions are an excerpt from his information.

Create a Strong Name Assembly

  1. Create a strong name for your web part (if you have not already done so), using sn-k c:keypair.snk.
  2. Add the key pair file to the project containing your web part.
  3. In the webpart project properties, sign the assembly using the key pair.

Create a Manifest File

  1. Add a new XML file to the webpart project, name this file manifest.xml.
  2. Add the following code to the XML file…
       1: <?xml version="1.0" encoding="utf-8" ?>
       2: <Solution xmlns="http://schemas.microsoft.com/sharepoint/"
       3:           SolutionId="AF597DAB-65D7-4c1a-A012-D04184CA647E">
       4:     <Assemblies>
       5:         <Assembly DeploymentTarget="WebApplication"
       6:             Location="SPDataPart.dll">
       7:             <SafeControls>
       8:                 <SafeControl
       9:                     Assembly="SPDataPart, Version=1.0.0.0, Culture=neutral, PublicKeyToken=8c9fc716f38d08b2"
      10:                     Namespace="SPDataPart" TypeName="*"/>
      11:             </SafeControls>
      12:         </Assembly>
      13:     </Assemblies>
      14: </Solution>
  3. Change the details in to match your webpart DLL name, strong name, and public key token.
  4. Note: If creating XML solution file is not your thing, Scot talks about a Visual Studio template on CodePlex to make solution file creation easier – link.

Create the Solution Package

  1. Add a new “CAB Project” to the solution, alongside the webpart project.
  2. Add “Project Output/Primary Output” from the webpart project to the CAB project – this adds the webpart DLL to the CAB.
  3. Add “Project Output/Content Files” from the webpart project to the CAB project – this adds the manifest file to the CAB.
  4. Build the entire solution.
  5. Find the CAB file in the bin/[Debug|Release] folder for the CAB project and rename the CAB extension to WSP.
  6. You now have a Web Solution Package.

Deploying Solution to SharePoint

  1. Run the following command on the SharePoint box to install the solution:

    stsadm.exe -o addsolution -filename PathToMyWSPFile.wsp

  2. Open SharePoint Central Administration Console.
  3. Click the operations tab and then Solutions Management link.
  4. Click the solution package listed, which we added in step 1 of this section
  5. From the package options page, click deploy.
  6. Navigate to the top level site containing the web part.
  7. Go to the web part gallery under site settings.
  8. Click the New button.
  9. Check the webpart(s) from the list to add to the site.
  10. You are now ready to add the webpart to web part zones within the site.

One thought on “Deploying a WebPart in SharePoint 2007

Comments are closed.