SharePoint List.getListItems WebService to return sub folder contents, recursively

18,998

Solution 1

It is possible to get the list contents recursively, using <ViewAttributes Scope="RecursiveAll"/> elment. There is a silly mistake in my soap envelope. The queryOptions element has no namespace. I fixed in the following text.

<soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope" xmlns:soap1="http://schemas.microsoft.com/sharepoint/soap/">
   <soap:Header/>
   <soap:Body>
      <soap1:GetListItems>
         <soap1:listName>Shared Documents</soap1:listName>
       <**soap1:**queryOptions> 
        <QueryOptions> 
           <IncludeMandatoryColumns>TRUE</IncludeMandatoryColumns>
           <ViewAttributes Scope="RecursiveAll"/>
           <DateInUtc>TRUE</DateInUtc>               
        </QueryOptions>
      </**soap1:**queryOptions> 
      </soap1:GetListItems>
   </soap:Body>
</soap:Envelope>

Btw, there is a great tool, U2U CAML Builder to build SharePoint CAML. I wish I found that a few weeks ago.

Solution 2

You have to recursively call the service to get all the items within the subfolders. I don't there is an option to do it OOTB. Instead, you can always write your custom SharePoint web service to accomplish this.

  1. http://social.msdn.microsoft.com/Forums/en-US/sharepointdevelopment/thread/16a2d993-2f5e-4242-8e5a-451a78c064a3
  2. http://blogs.msdn.com/b/karthick/archive/2006/03/27/562245.aspx
Share:
18,998
so_mv
Author by

so_mv

Updated on July 18, 2022

Comments

  • so_mv
    so_mv almost 2 years

    I am calling the lists.asmx webservice from CXF. The following soap call does not return files from list sub folders. It returns folder1,folder2 and file1.pdf

    Shared Documents
      folder1
         file2.docx
         file3.pdf
      folder2
         sub-folder1
            file5.pdf
         file4.pdf
      file1.pdf
    

    SOAP call

    POST /_vti_bin/lists.asmx HTTP/1.1 Accept-Encoding: gzip,deflate
    
    <soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope" xmlns:soap1="http://schemas.microsoft.com/sharepoint/soap/">
       <soap:Header/>
       <soap:Body>
          <soap1:GetListItems>
             <soap1:listName>Shared Documents</soap1:listName>
           <queryOptions> 
            <QueryOptions> 
               <IncludeMandatoryColumns>TRUE</IncludeMandatoryColumns>
               <ViewAttributes Scope="RecursiveAll"/>
               <DateInUtc>TRUE</DateInUtc>               
            </QueryOptions>
          </queryOptions> 
          </soap1:GetListItems>
       </soap:Body>
    </soap:Envelope>
    

    Any clues on how to get files from folder1, folder3 and sub-folder1 included in the result?. If Lists web service cannot do it, is there an alternative service/method?

    Additional Information: There is another webservice, SiteData (_vti_bin/sitedata.asmx). It has a similar method ( getListItems) and returns all files with just the list name and no additional parameters.The issue is I could not figure out how/where to specify the Paging parameter, as there is NO queryOptions input element like in the Lists webservice.

     <soap1:strListName>?</soap1:strListName>
     <soap1:strQuery>?</soap1:strQuery>
     <soap1:strViewFields>?</soap1:strViewFields>
     <soap1:uRowLimit>?</soap1:uRowLimit>
    
  • so_mv
    so_mv almost 13 years
    Thanks. The issue is in the soap envelope above.
  • Abhay Chaware
    Abhay Chaware about 10 years
    i am getting Response code: 400, Response message: Bad Request, when I add soap1: lines .. am i missing something ?
  • Vijay Kumar
    Vijay Kumar almost 6 years
    i tried with same request for getting all the folders and files inside given list. But it gave me only top level files and folders. Any suggestions