Tuesday, March 04, 2008

SharePoint MOSS 2007: Can we create a union of a Document Library and A Pages Library?

The short answer:
No, not directly in the web interface via a Content Query web part. (The work around I used is at the bottom of this article, if you want to just skip to that)

The long drawn out answer/explanation/example ...
I have a Web Publishing site on my MOSS 2007 Server. I have both Office word/excel/powerpoint documents and web pages to display in my site. I add pages using the web interface, selecting the articles page template so that my users can manage the content. Web pages go into the site Page Library. That works great. I upload documents into the site’s Document Library. That works fine too. Now, consider we need to be able to display documents directly on the site. That works by manually adding hyperlinks to content just fine. Now, here comes the problem...

Both my office documents AND my pages, now stored in different Library types, need to be listed in the same results query within a Web Part. Basically, my users consider both types of files to be "Articles". They should all be merged together into one list, sorted by date descending, for display in a "whats new" page. So, if I have a word document called "Article1.docx" and a web page called "Article2.aspx" I need the list to show in a web part like this:


Article1 (Article1.docx)
Article2 (Article2.aspx)
...

Lets take a look at how we might attempt to do this in MOSS out of the box:



Here you can see we have a Document Library and a Page Library in our Articles site. Both libraries currently contain files: 2 office documents and 4 web pages. The goal, again, is to merge and sort these results into one list of links for display on a whats new page. Lets create the page and play with our out of the box webparts:



Above is a Welcome page for the Articles site. I’ve added 2 Web Parts. Both are "Content Query Tool Part" types. The first Web Part gets all the results from the Pages library, the second gets the Documents Library results. Why didn’t I just use one Web Part to display all the data? Check out the interface in the screenshot for configuring the query section for the Content Query Web Part. The Content Query Web Part forces you to filter by a single List/Library Type ... and as you can see, two types at that level are "Document Library" and "Pages Library". The two types can not be combined at all via this web part.

So..what do we do now?

First thought: stick to using 1 type of List/Library for all your content (if you can).

If you need more than one list type for whatever reason, then you could try to dig into Sharepoint Designer and attempt to join the two List types via XML web service calls, then figure out how to display the returned XML data in a custom web part.

Finally, there may be a way to do this with a custom List type defined at the site level. I don’t know how custom lists work yet, so this is just a guess on my part.

Moving to a single List type solved my problem

In my case, I was able to use a single list type ... though I don't know what problems might come up down the road from doing it this way. I moved all of my office documents from the Document Library to the Page Library using the "Site Actions->Manage Content and Structure" tool. Then I changed the the Content Query Web Part to pull All Content Types from the Pages Library:

No comments: