tags:

views:

636

answers:

2

How do you deploy a webpart within a feature?

i have my webpart as MyWebPart.cs file.

ive got got a feature which is used for something else. im just wondering if i can deploy this webpart along with the feature.

+4  A: 

The easiest way I've found is to use a tool such as WSPBuilder. This integrates with Visual Studio and allows you to create a new web part with feature.

Try this out and incorporate the existing code and feature you've already written. I guarantee it will save you a lot of time compared to doing everything manually.

VSeWSS may also do the job but I've never found it as easy to use.

Alex Angas
Agreed, WSPBuilder is absolutely the easiest way to build .wsp's.
Dana
Im deploying the feature with wspbuilder, but what i want to know is if i need to do anything else (do i need other files)? or is it just a matter of having a single webpart class
raklos
+10000000 for WSPBuilder
Jason Watts
+3  A: 

So I guess you need help with deploying a webpart through a feature. Here´s how to do that.

In your elements.xml file (in the feature) add a module, like:

<Elements  xmlns="http://schemas.microsoft.com/sharepoint/"&gt;  
  <Module Name="WebParts" List="113" Url="_catalogs/wp" Path="DWP">
    <File Url="MyWebpart.webpart" Type="GhostableInLibrary">
      <Property Name="Group" Value="MyWebPartGroup"></Property>
    </File>
  </Module>
</Elements>

The Path (DWP) is a folder in the feature where the actual .webpart file is stored and it can look like this:

<webParts>
  <webPart xmlns="http://schemas.microsoft.com/WebPart/v3"&gt;
    <metaData>
      <type name="Full class name, Full 4-part assembly name" />
      <importErrorMessage>Import error message</importErrorMessage>
    </metaData>
    <data>
      <properties>
        <property name="Title" type="string">My webpart</property>
        <property name="Description" type="string">Description of WP</property>
      </properties>
    </data>
  </webPart>
</webParts>

Using wsp builder to package this into a wsp makes things with safecontrols and DLL deployment etc so much easier so use that...

Johan Leino