Programmatically Updating Page Web Part Views (XsltListViewWebPart)

For each Web Part view (XsltListViewWebPart) added to any page, SharePoint creates a corresponding hidden view within the associated list. The view XML code contained within the page itself (shown below) will automatically sync with the hidden view when any edits are made to the view. (Such as when you edit the web part within the browser and select 'Edit the current view'.) You'll witness this sync enforcement firsthand if you try to edit the hidden view outside the browser page edit path, either by attempting it programmatically or copy/pasting the hidden view edit URL within the browser. Either of those methods will likely generate a "The file is not checked out. You must first check out this document before making changes" error. This is because the page containing the hidden view web part is often contained within a publishing library requiring document check out before editing and any edits to the hidden view will automatically invoke an update of the corresponding XML within the page itself.

You may find yourself in a situation requiring the programmatic update of a number of such views within the pages. For example, if you were utilizing the inherent ContentType field for grouping or filtering based on 'Begins With' or 'Contains' within any web part views - these views will no longer work after upgrading to SharePoint 2010. It seems Microsoft quietly changed the 'ContentType' field from a 'Text' type in 2007 to a 'Computed' (Calculated) type in 2010. This results in an inability to use that field for any grouping and certain filtering utilities. Consequently, we needed to edit A LOT of pages containing XsltListViewWebPart which were using the ContentType field for grouping and filtering.

As it turns out, you don't need to edit the pages themselves (Yay!), simply update the hidden views associated with the relevant list and the pages will automatically update. Just be sure to disable the check-out requirement if it exists on the page libraries before attempting to update the hidden views programmtically.

Posted on 8/1/2012 11:44:00 AM by sterlingt

Permalink | Comments (0) | Post RSSRSS comment feed |



Related posts