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:

http://sqlblogcasts.com/blogs/drjohn/archive/2007/11/02/Getting-a-list-of-files-from-a-moss-document-library-using-a-SharePoint-web-service.aspx

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:

http://msdn2.microsoft.com/en-us/library/lists.lists.getlistitems.aspx

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:
http://blog.krichie.com/2007/01/30/traversing-sharepoint-list-folder-hierarchies/

No comments: