Wednesday, January 17, 2007

Grouping Documents By More Than Two Levels

We are all very used to organizing our documents by folders. We have been doing it for years in File Explorer. But it does have it's drawbacks. For example you can only organize a set of documents in one way. You might have reports that you file by region. If you wanted to see them by Customer instead, you are stuffed.

Then SharePoint came along and provided meta-data. Now we have the ability to tag our documents with the relevant properties (such as Region and Customer). We can define views based on these properties to see our documents in many different ways. We can even combine folders and meta-data so that users can continue to file documents in folders, while at the same time providing views based on the meta-data.


The "Group By" view option allows you to define a hierarchy for viewing the documents - say by Country and then by Region. But what if you need to go beyond two levels? What if you want to view documents by Country, Region and Store? This article explains how you can achieve this using SharePoint Designer and WSSv3 (most of this is the same in FrontPage 2003 and WSSv2).


I will assume that you already have a document library with the necessary meta-data. To make it more interesting, I'm going to also assume that your documents are stored in a folder structure within the document library.

  1. Launch SharePoint Designer and open your site (File - Open Site...)

  2. Open the default.aspx file in your site. We will place our web part on this page

  3. Select the Data Source Library tab in the right hand task pane

  4. Open the drop down listbox for your Document Library and choose Copy and Modify...
    Copy and Modify


  5. On the Source tab, change the Item and folder scope to RecursiveAll

    Data Source Properties - Source


  6. On the General tab give a meaningful name to this Data Source and click OK

    Data Source Properties - General


  7. Drag and drop your new data source onto a web part zone. Now click on the > button on the right-hand-side of your new web part. You will see the following menu, select Sort and Group:

    Sort and Group


  8. Use the Add >> button to specify the fields you want to group your data for. Click on the Show group header checkbox for each of the fields you move across. Click OK once you have finished.


  9. Now from the right-hand-side menu select the Filter option. Specify the filter shown below. This will make sure that folders are not displayed in your web part. Click OK and you are done.

    Filter Criteria

This works if your web part is going to be on the same sub site as the document library. In my next post I'll show you how you can do this with a document library from another site.


Note: I've noticed that once you get to four levels, the web part does not correctly group items. It basically uses the first value it finds to group all items at each of the 4-level-deep branches. If I find a fix to this, I'll let you know.