Exporting the XSLT List View Web Part in SharePoint 2010

The XSLT List View Web Part (XLV web part) is one of the great additions in SharePoint 2010. Why is it great? Well other than a lot of cool stuff under-the-hood it means that the end user can re-use custom styles, apply conditional formatting and many other rich customisations to the way their list data is displayed. The SharePoint Designer team blog posted a good article introducing the XLV back in 2009.

On the downside however, much of this greatness seems locked into SharePoint Designer 2010 though, which doesn’t seem fair! Actually, it is fair as one of the benefits of the behind-the-scenes changes to the list views is that you now have a very powerful and easy to use tool with which to customise your presentation. This is a big step forward in end-user empowerment and overall a really positive step in my view.

[That said, the whole SPD should you or shouldn’t you debate is valid – and one that I’m not going to get into here. If you’d like further reading then I’d suggest checking our Kerri Abraham’s article on NBSP: SPD SharePoint Emancipation]

So, what about those people who want to do some cool stuff with the XLV web part but yet are in a locked down environment and do not have access to SharePoint Designer? Well it is possible to make really quick changes without SPD at all. The first thing you need to be able to do though is ‘get hold’ of a XLV that you can begin to edit. Exporting the web part is the answer here… but hold on – 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" ?>
	<webPart xmlns="http://schemas.microsoft.com/WebPart/v3">
			<type name="Microsoft.SharePoint.WebPartPages.XsltListViewWebPart, Microsoft.SharePoint, Version=, Culture=neutral, PublicKeyToken=71e9bce111e9429c" />
			<importErrorMessage>Cannot import this Web Part.</importErrorMessage>
				<property name="ListUrl" type="string">Lists/CustomList</property>				
				<property name="ExportMode" type="exportmode">All</property>				

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

  5. Add the web part to the page – and note the option to export is now available!
  6. XLV Web Part With Export Option

  7. 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. In my next couple of posts I’ll hopefully show you a couple of simple changes that you can make to start to make the most of the export option.

*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.

Update 05/07/11: After regularly using the technique, I’ve finally written up a post on how this can be done for a list from a different site.

Update 06/04/11: If you’re interested in possible uses of this I’ve added a post on changing the default message displayed when there are no items in an XSLT list view web part that relies upon this export technique.

share and enjoy
  • Print
  • Twitter
  • Digg
  • del.icio.us
  • StumbleUpon
  • Yahoo! Buzz
  • Google Bookmarks
  • Facebook

15 comments to Exporting the XSLT List View Web Part in SharePoint 2010

Leave a Reply

You can use these HTML tags

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>