A little while ago I wrote how it was possible to create an XSLT List View Web Part that could be exported. Whilst this is very useful, I actually find myself using a similar technique more often for displaying an XLV for a list on a different site from where has been created.
For example, with just a few lines I can display an XLV of a site from the root of my site collection on a sub-site. (As per my previous post, I’m well aware that this is possible in with SharePoint Designer – but not everybody is in a position where that’s an option!)
<?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=184.108.40.206, Culture=neutral, PublicKeyToken=71e9bce111e9429c" /> <importErrorMessage>Cannot import this Web Part.</importErrorMessage> </metaData> <data> <properties> <property name="Title" type="string">My Web Part</property> <property name="ListName" type="string">B8381C7D-3B8D-46D8-8E40-C96E1FF4C308</property> <property name="ListId" type="string">B8381C7D-3B8D-46D8-8E40-C96E1FF4C308</property> <property name="WebId" type="System.Guid, mscorlib, Version=220.127.116.11, Culture=neutral, PublicKeyToken=b77a5c561934e089">adea17f7-e661-4ff0-91e9-70f021c60647</property> <property name="ExportMode" type="exportmode">All</property> </properties> </data> </webPart> </webParts>
The main differences here from displaying a list on the current site is adding in the properties for WebId and (bizarrely) ListName withGUIDs and replacing ListUrl with ListId.
With the above code it’s then simply a case of:
- Update the sample GUIDs in the above code (after locating the correct web and list IDs)
- Save as a .webpart file
- Edit a page and upload the web part
- Add the web part to the page; modifying the properties as desired