Monday, 14 January 2008

MOSS - Getting a all items within a Sharepoint List recursively

When you query a list in MOSS, you only get the top level folders by default. If you have a folder hierarchy within your Sharepoint 2007 list, you will not see the documents underneath the top level of your list. It is important to note that you shouldn't go through each folder in this top level and then querying each folder for a list again. Instead, you should just use the Scope="Recursive" setting
(Add to your queryoptions Xml fragment).

For more info, see the following:

There is also an element you can add to the the Xml fragment to to restrict the results to one folder - the "Folders" element. For more details, see:

For example, to recursively get all documents in folder a folder named "Folder 10", your Xml fragment would be

"<queryoptions><viewattributes scope="\"><folder>Folder 10</folder></queryoptions>"

Another article I found useful on recursively enumerating folder contents is at:

No comments: