user3173418
user3173418

Reputation: 21

ViewAttributes Recursive Scope not working SharePoint 2013 CAML Query to fetch all files from document library recursively

I have a document library SP 2013 and want to get all the documents from all folders and sub folders. I don't want any folders but I do want to get all the files from each folder.

Using SP 2010 U2U CAML Builder, I have made below query:

<query>
<QueryOptions>
        <ViewAttributes Scope="Recursive" />
    </QueryOptions> 
</query>

This query is working fine with libraries in SP 2010, but it is not working with SP 2013

Below is the code for fetching data from SP 2013 library

CAMLQuery = "<soapenv:Envelope xmlns:soapenv='http://schemas.xmlsoap.org/soap/envelope/'>\
  <soapenv:Body>\
    <GetListItems xmlns='http://schemas.microsoft.com/sharepoint/soap/'>\
      <listName>My Document Library</listName>\
<query>\
<QueryOptions>\
        <ViewAttributes Scope="Recursive" />\
    </QueryOptions> \
</query>\
    </GetListItems>\
  </soapenv:Body>\
</soapenv:Envelope>";

$.ajax({
    url: "https://<server>/teams/<siteName>/_vti_bin/lists.asmx",
    type: "POST",
    dataType: "xml",
    data: CAMLQuery,
    complete: getGrid,
    contentType: "text/xml; charset=\"utf-8\""
});

getGrid is callback function on completion

Please help me with this.

Upvotes: 2

Views: 13544

Answers (2)

SpThangu
SpThangu

Reputation: 1

Please use the SP.ViewScope property to update the View Scope For Recursive, the value is 1.

var view= list.get_views().getByTitle("YourView"); view.set_scope(2);

https://msdn.microsoft.com/en-us/library/office/ee548053(v=office.14).aspx

Upvotes: 0

derBasti
derBasti

Reputation: 325

you have to give the scope in the view-tag, like this:

<View Scope="RecursiveAll">
    <Query>
        <Where>...</Where>
    </Query>
</View>

Upvotes: 11

Related Questions