I have seen a lot of examples and questions about this out there but nothing I have found has helped me accomplish this. I need to be able to grab all the names of the documents within a given library, including all those that may exist within subfolders recursively.
Here is what I have:
function documentQuery(listName) {
var ctx = new SP.ClientContext.get_current();
var oLibDocs = ctx.get_web().get_lists().getByTitle(listName);
var caml = new SP.CamlQuery();
caml.ViewXml = "<View Scope='RecursiveAll'></View>";
this.allDocumentsCol = oLibDocs.getItems(caml);
ctx.load(this.allDocumentsCol, "Include(FileLeafRef, ServerUrl)");
ctx.executeQueryAsync(Function.createDelegate(this, this.onSucceededCallback), Function.createDelegate(this, this.onFailedCallback));
}
function onSucceededCallback(sender, args) {
var libList= "";
var ListEnumerator = this.allDocumentsCol.getEnumerator();
while(ListEnumerator.moveNext())
{
var currentItem = ListEnumerator.get_current();
var currentItemURL = domURL + currentItem.get_item('ServerUrl');
libList += currentItem.get_item('FileLeafRef') + ' : ' + currentItemURL + '\n';
}
alert(libList);
}
function onFailedCallback(sender, args) {
alert("failed. Message:" + args.get_message());
}
so this works for all the first level documents, but also returns folder names. I thought the
I have tried RecursiveAll instead, I have tried placing it in ViewAttributes, I have tried having Recursive within View and adding FilesOnly to ViewAttributes to try to at least eliminate the folder names. none of this has worked.
so the basic thing i am looking to do is get the above idea (or something like it) to work by checking all items recursively (including all sub folders), but also return (alert in this case) only those that are files. this is ECMA/JSOM as I only have access to SPD.
any help with this is appreciated as always.
UPDATE: so SPServices works by adding the following to GetListItems:
CAMLQueryOptions: '<QueryOptions><ViewAttributes Scope="Recursive"/></QueryOptions>',
SPServices is awesome and I use if frequently, but there are certain cases where I need async operations and this is one of them. I have since tried modifying the CAML in the COM example but I can't seem to get it right to replicate this....any ideas?