Merging document libraries using Content Query Web Part

Recently I had an requirement to merge more than one document library in same site collection. My first attempt was to find “no code” solution and use SharePoint built in capabilities. After some Google attempt found we can accomplish this using Content Query Web Part or Data View Web Part. There are plenty of posts which explains “connecting another document library using data view web part in SharePoint Designer 2007” but they are irrelevant for SharePoint Designer 2010 ( or Am I missing something ? ). Why ? Because SharePoint Designer 2010 data source picker is missing important feature Connect to another library link.

Some says it can now achieved using SOAP Service Connection and REST Service Connection in SharePoint Designer 2010 but I’m not able to merge though I can get the library from other sites.

At the end I realized only Content Query Web Part may help me to accomplish this. However, I don’t find any help over Internet which explains start to end steps which I can follow and accomplish this ( or I’m poor Googler ). Most important point I was missing is to merge libraries using “CQWP” you must have one common content type for all those libraries which you want to merge. Let’s move on and see how it can be done ..

  • First create new content type which will use by my libraries later.To do so, Go to Site Settings-Galleries-Site content types and Create new Content type. Here is my Customer content type,

  • Created two Customer libraries in two different sites using above content type and added some documents.

  • Add Content Query web part on the page and click Edit Web part link to customize it. Expand Query section and select top level site collection.

  • Under List Type, Select Custom List and choose the content type.

  • Save the settings and documents from both the the libraries will appear like,

By default you can see only Title column until you modify ItemStyle.xsl file . To do so you should follow the Heather Solomon’s article about customizing content query web part.

So here is my customize ItemStyle.xsl ,

<xsl:template name="ConsolidateListStyle" match="Row[@Style='ConsolidateListStyle']" 

		<xsl:variable name="SafeLinkUrl">
            <xsl:call-template name="OuterTemplate.GetSafeLink">
                <xsl:with-param name="UrlColumnName" select="'LinkUrl'"/>
        <xsl:variable name="SafeImageUrl">
            <xsl:call-template name="OuterTemplate.GetSafeStaticUrl">
                <xsl:with-param name="UrlColumnName" select="'ImageUrl'"/>
        <xsl:variable name="DisplayTitle">
            <xsl:call-template name="OuterTemplate.GetTitle">
                <xsl:with-param name="Title" select="@Title"/>
                <xsl:with-param name="UrlColumnName" select="'LinkUrl'"/>
        <xsl:variable name="LinkTarget">
            <xsl:if test="@OpenInNewWindow = 'True'" >_blank</xsl:if>

      	 <table cellpadding="7" cellspacing="7" border="1" width="100%">
           	   <td valign="top" style="width:25%;">
	             <xsl:call-template name="OuterTemplate.CallPresenceStatusIconTemplate"/>
                	<a href="{$SafeLinkUrl}" target="{$LinkTarget}" title="{@LinkToolTip}">
                     	<xsl:value-of select="$DisplayTitle"/>
                 <td valign="top" style="width:25%;">
                   	<xsl:value-of select="@Customer_x005F_x0020_Name" />
	            <td  valign="top" style="width:25%;">
                   	<xsl:value-of select="@Country" />
            	<td valign="top" style="width:25%;">
                   	<xsl:value-of select="@Phone" />

Here is the result,

When I presented this solution to my manager he said “Let’s group the docs on Country” :). Now I don’t want to dig more in customizing xsl so decided to write custom C# code for the same. It’s going to be my next article 🙂