Reusing SharePoint ListView and ListForm Web Parts
When creating custom pages in SharePoint, you may, at some point, simply want to display a ListView web part (XsltListViewWebPart
) to display a whole view of a list on your custom page, or you might want to display only a list form. A list form might be the default Display, Edit, or New forms. You may want to create these on your own custom page instead of editing or overriding the default Display, Edit, or New forms so that both are usable, or you might want one of the forms displayed as part of a larger page with custom code behind, etc.
I discuss setting up custom application pages in SharePoint in this post, which covers copying the web part code out of SharePoint designer and then resolving the necessary properties. To reiterate - it's necessary to re-set any or all of these properties, so the web part can resolve and work properly after the GUIDs have been regenerated (say, re-deploying): ListId
, ListUrl
, ViewGuid
, or ListItemId
.
Here's a gist of the second utility method I wrote - this one to resolve ListFormWebParts (the first is in Creating Application Pages in SharePoint):