DWP WebPart in SharePoint 2010

I have just had a requirement to create a dwp web part in SharePoint 2010 using Visual Studio 2010, what I thought would be a simple task was not as easy as I first thought due to the new packaging and deployment built into Visual Studio. This is the method I used (right or wrong, use at your own risk! I take no resposiblity for damage caused, lost time, alien invasion etc…).

Ok first create an empty SharePoint 2010 project and add a webpart to it.

Expand the part created and locate the <yourpartname>.webpart file and delete it.

Add a new file (use the text file item) called <yourpartname>.dwp at the same level.

Open the text file and paste the following into it:

<?xml version="1.0" encoding="utf-8"?>
<WebPart xmlns="http://schemas.microsoft.com/WebPart/v2" >
  <Title>Your part title</Title>
  <Description>Your part description.</Description>
  <Assembly>Your type name, $SharePoint.Project.AssemblyFullName$</Assembly>
  <TypeName>Your type name</TypeName>
Edit as required to match your assembly etc.
In solution explorer right click the web part and open folder in explorer, or just browse to the web part folder in explorer.
Locate the SharePointProjectItem.spdata file and open it in notepad.
In the ProjectItem > Files section of the xml duplicate the ProjectItemFile line with elements in it, now update the Source attribute value to your dwp file and change the Type to ElementFile as shown below:

<ProjectItemFile Source="Elements.xml" Target="GroupPart" Type="ElementManifest" />
<ProjectItemFile Source="GroupPart.dwp" Target="GroupPart" Type="ElementFile" />
Save the file and return to Visual Studio, build and deploy and all should be good!
Hope someone finds this useful it took me an hour to figure it out!

Leave a Reply

Your email address will not be published. Required fields are marked *