I'm no stranger to this error or the various solutions, but this one has me scratching my head. I'm using JavaScript object model to get all a list of all the files in a given folder. I get the error on the getEnumerator in the code below. I've stripped the code down to the bare minimum:
function getFilesInFolder() {
var folderServerRelativeUrl = folderPath + ID;
var context = new SP.ClientContext.get_current();
var web = context.get_web();
var list = web.get_lists().getByTitle(documentLibraryName);
var query = SP.CamlQuery.createAllItemsQuery();
query.set_folderServerRelativeUrl(folderServerRelativeUrl);
//Update "web part" link
$("#doclink").attr('href',folderServerRelativeUrl);
files = list.getItems(query)
context.load(files, 'Include(Id)');
context.executeQueryAsync(Function.createDelegate(this, this.OnSuccess), Function.createDelegate(this, this.OnFailure));
}
function OnSuccess()
{
//ERROR Next Line:
var listItemEnumerator = this.files.getEnumerator();
var table = $("#attachments");
while (listItemEnumerator.moveNext())
{
console.log("Found a file");
}
}
The code is called as such in the beginning of the file: $(document).ready(function(){ //Other code... ExecuteorDelayUntilScriptLoaded(getFilesInFolder,"sp.js"); });
I've tried a ton of variations on this AND it used to work (not sure what changed either server or client-side).