1

I am trying to retrieve all the records from a document library in Sharepoint. This library consists of folders, subfolders, and files. I am able to use MSXML2.XMLHTTP60 to get to the document library.

strRequest = "<?xml version='1.0' encoding='utf-8'?>" & _
"<soap:Envelope xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' xmlns:xsd='http://www.w3.org/2001/XMLSchema' xmlns:soap='http://schemas.xmlsoap.org/soap/envelope/'>" & _
"  <soap:Body>" & _
"    <GetListItems xmlns='http://schemas.microsoft.com/sharepoint/soap/'>" & _
"      <listName>{FC3E18D6-33E5-4032-BE4B-F0F92F6F18BA}</listName>" + _
"      <viewFields><ViewFields>" & _
"      <FieldRef Name='ID'></FieldRef>" & _
"      </ViewFields></viewFields>" & _
"    </GetListItems>" & _
"  </soap:Body>" & _
"</soap:Envelope>"

Set xmlHTTP = CreateObject("MSXML2.XMLHTTP")
xmlHTTP.Open "POST", strURL, False
xmlHTTP.setRequestHeader "Content-Type", "text/xml; charset=utf-8"
xmlHTTP.setRequestHeader "SOAPAction", "http://schemas.microsoft.com/sharepoint/soap/GetListItems"
xmlHTTP.send strRequest

This will retrieve everything at the root folder of the document library (folders and files but no subfolders/subfiles). How do I modify or add to this code to retrieve everything including ALL files from this Document Library including files in subfolders?

After retrieving the list of files, I put it into an MSXML2.DOMDocument.3.0 object to iterate through and retrieve fields for each file.

JimC
  • 99
  • 2
  • 16

1 Answers1

0

You should be able to do this using ViewAttributes element with "RecursiveAll" scope inside QueryOptions. Just put it after ViewFiels I cannot check this, but something like that:

<QueryOptions>
    <ViewAttributes Scope='RecursiveAll'/>
</QueryOptions>

Some documentation of ViewAttributes:

A string representing all attributes returned as part of the View element when retrieving a view through the GetView method. This element is optional, and its default value is empty. If a viewName parameter is supplied, the view attributes from the persisted view are used. When this argument is supplied, it overrides any view attributes that can be retrieved from the persisted view specified by the viewName parameter. This element is optional and its default value is an empty string. To return all documents in a library, the ViewAttributes element is used as follows: < ViewAttributes Scope="Recursive" />. https://learn.microsoft.com/en-us/previous-versions/office/developer/sharepoint-2010/bb263567%28v%3doffice.14%29

Here there's also some VB example of using this web service, although without query options: https://msdn.microsoft.com/en-us/library/websvclists.lists.getlistitems.aspx?f=255&MSPPError=-2147217396&cs-save-lang=1&cs-lang=csharp#code-snippet-5

If the above solution won't work, search for "CAML" because that's how this markup is called.

Marcin Robaszyński
  • 772
  • 1
  • 11
  • 21
  • Thanks for the response Marcin. We ended up solving it a different way before your reply. We created a view on Sharepoint and added {...} to the request and was able to retrieve all records. – JimC Nov 01 '18 at 16:10