Mar 16, 2009

Share a Document Library among different sites

There are many times people ask: how to share a whole document library among different sites? You can of course do with DVWP or CQWP, but neither of them gives a good user interface. You can also use LinkTo content type, but that is an item-by-item solution.
There is a third addons: http://stsadm.blogspot.com/2008/08/adding-list-view-web-part-to-page.html but it requires server access and intallation.

We know list view web part can perfectly display a document library, but OOB it can only be added within same site. Is there a workaround?

The answer is yes, since we all know we can convert List View webpart into DVWP, and then we can export to a .webpart file and then import it to any site in the collection.

If you just do that, you will get a generic error. The problem is, in the .webpart file, only listId is specified, no WebUrl.

We need to add WebUrl:

1) open .webpart file in any editor
2) search and find "ListID", there are 3 of them
3) after each "ListID" add the followings:

<asp:Parameter DefaultValue="siteName" Name="WebUrl" />


After saving the change, import it to any site in the collection, you will see it works just like a charm.

BTW, Even though you need to use SPD when converting LVWP to DVWP, you can avoid un-ghosting by deleting the page containing the initial LVWP.


a great idea on how to deploy DVWP from one farm to another: http://mdasblog.wordpress.com/2008/12/16/replacing-listids-with-listnames-in-data-view-web-parts/