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.
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:
Some documentation of ViewAttributes:
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.