Combine Multiple Libraries into a Single DVWP

I was working on a Document Center today in SharePoint 2010, and needed to create a web part that will show a rolled up view of multiple document libraries in the same site collection. The following steps outline how to accomplish this:

You will need to open up SharePoint designer and navigate to the page in which you want the web part to reside.

First go to datasources in the left nav.

Click Create Linked Datasource.

﻿

Choose Configure Linked Datasource in the Wizard.

From the list that comes up, choose the document libraries you wish to join together in the view. Keep in mind that this is using a left join and so the more libraries and the more columns you have the more intensive this query becomes.

Click next and choose to merge the contents of the datasources and click Finish.

For each of the libraries you chose, select Edit. You will see the following menu:

You can add or remove fields from the query, Filter out certain items based on fields and configure default sorting.

Once you have your datasource configured click ok and you will see it listed under Linked Datasources in your datasources menu.

Now navigate to the page in which you plan to place your webpart. Open advanced mode, change focus to the web part zone you wish to place the web part in, and in the top nav choose data view and select the datasource you just created.

This will add a new webpart (similar to the list view web part from the UI) to the web part zone. You will notice one thing right off the bat. Designer shows the URL to the document, but it is not actually a hyperlink. If you wish to modify this, I grabbed Name of the document and used that as the text of the hyper link and the href to the URL.

To do this in the split-view select one of the cells that contains the URL:

This will highlight the code above. You will notice that the cell’s code currently looks like this:

<value-of select=“@FileRef”/>

Make the following changes: <a href=“{@FileRef}“><xsl:value-of select=“@FileLeafRef” /></a>

@FileRef is the URL to the document and @FileLeafRef is the name of the document.

One other thing I ran into is my document libraries had lookup columns to a list. When the dataview rendered the view, those values were rendered as plain text and not HTML.

Following the same steps as above, you will see the code looks like this:<xsl:value-ofselect=“@Entity”/>

Add the following code to this element so that it looks like this:<xsl:value-ofselect=“@Entity”disable-output-escaping=“yes”/>

This tells SharePoint to render the HTML in the field as opposed to displaying it as text. This will allow the lookup columns to display correctly. This should also resolve the issue for any other columns that render as text instead of HTML. See this KB article for reference: http://support.microsoft.com/kb/264665

This solution is for Libraries residing within the same Site Collection. I will update this post as I continue to work with this Document Center and will note any other issues or helpful hints I run across.