2

I am developing a custom sharepoint solution with Visual Studio. The Solution contains an application page, it creates lists in the featur event receiver and so on. I'd like to deploy some pre-filled content editor webparts and some modified list views within the solution. The views were edited with SharePoint Designer and contain conditional formatting and an additional button column, I don't know how to create such a view programmatically. What is the best practice to deploy such things?

Thanks!

1

What I normally do when I want to add a webpart to a page using a feature (or Powershell for that matter) is the following:

  • Add the webpart to a page in your development environment. Customize it using the web interface. Add content to the content editor webpart.
  • Export the webpart as a .webpart or .dwp file.
  • Include the .webpart/.dwp file in your solution, as a feature element.
  • Let the feature receiver utilize the .webpart/.dwp file, import it and add it to the publishing page.

This allow you to make changes to the webparts by modifying the .webpart/.dwp file without having to rewrite your feature receiver.

You import and then add the .webpart/.dwp file to the page via the LimitedWebPartManager. The ImportWebPart method to import the file and then AddWebPart method to add it to the page.

This generally works fairly well for list view webparts to but you have to keep in mind to replace references to the list within the .webpart/.dwp files. I have never tried this approach with list views edited in SharePoint designer though.

  • Ok, how to exactly "Include the .webpart/.dwp file in your solution, as a feature element"? I tried adding it as an existing item but then it seems to be out of context. This is part of my initial question. – elsni Mar 11 '14 at 11:59
  • 1
    You can add the file to the feature as an element file. The file will then be “part” of the feature and be deployed to the feature folder with the WSP package. You add an empty element in Visual studio, add the element to your feature and then finally add the .webpart/.dwp file to the element. It’s the same principle as adding a file declaration with content types, a page layout etc. – Daniel Estelius Mar 11 '14 at 12:07
  • Thanks Daniel, do you also know how to include designer-modified views? – elsni Mar 12 '14 at 8:53
  • Ok, I saved the filled Content Editor WebPart as a .dwp file, created a blank element and a site scoped feature, added the dwp file to the element, renamed it to Elements.xml after delteing the default Elements.xml. The Feature can be activated, but the webpart does not show up in the web part gallery. What am I doing wrong? – elsni Mar 13 '14 at 9:10
  • I thought you were planning to use the feature to add the webparts to the page itself. If that was the case you wouldn’t need the webpart in the gallery. However- if you would like to add the file to the gallery you will have to alter the elements.xml file a bit. Something like: <Elements xmlns="schemas.microsoft.com/sharepoint" > <Module Name="MyName" List="113" Url="_catalogs/wp"> <File Path="Folder\MyWebpart.dwp" Url="MyWebpart.dwp" Type="GhostableInLibrary"> <Property Name="Group" Value="My Group" /> </File> </Module> </Elements> – Daniel Estelius Mar 13 '14 at 10:27

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.