Sunday, March 16, 2014

Exporting the XSLT List View Web Part in SharePoint 2010

 you can’t export a XSL list view web part.
XLV Web Part With No Export Option
As you can see in the above screenshot the ability to export an XLV has been disabled by default – but that is something that you can pretty easily turn back on. Admittedly at some point here SPD has was used for the following technique – but once it’s been used (i.e. once only by me) there’s no reason that you’ll ever need it to use it again once you have the following few lines of mark-up (i.e. you don’t need it!).
So, my approach involved opening up a page with an XLV in SPD and saving the web part file locally. I then simply edited the resulting file in notepad until it looked like the below code:
<?xml version="1.0" encoding="utf-8" ?><webParts> <webPart xmlns="http://schemas.microsoft.com/WebPart/v3"> <metaData> <type name="Microsoft.SharePoint.WebPartPages.XsltListViewWebPart, Microsoft.SharePoint, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" /> <importErrorMessage>Cannot import this Web Part.</importErrorMessage> </metaData> <data> <properties> <property name="ListUrl" type="string">Lists/CustomList</property> <property name="ExportMode" type="exportmode">All</property> </properties> </data> </webPart></webParts>
With this code I can carry out the following steps to give me an XLV that can be exported:
  1. Modify the ListUrl property to the site relative url of my list
    E.g. note here that in my example it is lists/customlist not /subsite/lists/customlist
  2. Save the file locally with an appropriate filename and the extension .webpart
  3. Edit a page on the same site* as the list and upload this web part
  4. Upload A Web Part

    4. Add the web part to the page – and note the option to export is now available!
    XLV Web Part With Export Option
    5. You should now be able to edit this web part just like any other XLV, e.g. modifying the view etc.
Now that we have the ability to export an XLV it is the first step in opening up some of those great features that are available in SPD for those situations where it’s simply not possible to use SPD itself. 
*As a final thought, this works for an XLV on the same site as the list you want to show – but what about if you wanted to show a list from a different site? Well, I think in this case you could replace the ListUrl property with the ListId and the WebId properties and that may work for you. When I get a moment I’ll confirm this.

No comments:

Post a Comment