SharePoint Lists Webservice – Traverse all Folders and Files

How can we produce a list of all files and folders inside a SharePoint List using the GetListItems method of the Lists.asmx webservice? As the webservice documentation is clearly lacking in some respects here’s an example of how to do it.

This post might seem a bit random but it took me quite some googling before I got the XML correct so I figured this might help someone else facing the same problem.

There’s no need to write a recursive function or anything, we simply specify the ViewAttributes parameter in the CAML query to produce a flat list of all the files (and folders) inside the list. The syntax might be a bit confusing so here’s an example using the List ID:

<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:xsi="" xmlns:xsd="" xmlns:soap="">
    <GetListItems xmlns="">
           <ViewAttributes Scope="RecursiveAll"/>

Without setting the

<ViewAttributes Scope="RecursiveAll"/>

we would only get items at the root level of the List. Note that we also added a rowLimit of 1000 as the standard rowLimit appears to be set to 100 when not specified. As you can see the QueryOptions needs to be embedded inside another queryOptions tag and will fail without it!

Leave a Reply


1 comment

  1. vladimir


    life saving!! thanks so much

Next ArticleBootstrap 2.0 Tabs JQuery Ajax Example