views:

412

answers:

1

Is it possible to get a list of all folders in a SharePoint document library, using SPQuery?

Something you could get in file system, if you opened Windows command prompt and ran

 dir /b /A:D /S

The problem is, if you create a simple SPQuery and set the viewAttributes to Scope='RecursiveAll', the result set contains items, but not the folders.

Or am I completely missing something?

Upd.: The reason for this question is (was) that I have to create a solution where a "packet of files" makes sense.
When my client speaks about a "document", he actually means an entity that may consist of multiple files and a common set of metadata for these files.

For instance, the document might be named "A letter to my grandma" (attributes: grandma's address, letter title), but it consists of several files: the actual letter in MS Word document and a JPEG picture.

So, the idea was that I could create a content type derived from Folder and add some fields to this content type (address, title). All the files placed into that folder would naturally become parts of the 'document'.

Since we expect that there will be a lot of such documents, we create a folder hierarchy of regular type of folders, too.

Now, we come to the question: how do I show a view like "Recent documents" to my client? This must work recursively to enumerate all the "documents". Recursion through SPFolder objects is way too slow due to the number of requests that have to be made. We hoped for a recursive SPQuery, but this does not seem to be solvable this way.

A: 

You should be able to get all the folders by filtering on the content type.

<Eq><FieldRef Name='ContentType' /><Value Type='Text'>Folder</Value></Eq>
Rob Windsor
This works for the items in the folder you are currently in. I have a folder hierarchy in which I have to pick out only _some_ specific folders (being of different content type). See my post update for details.
naivists