Search This Blog

Saturday, July 8, 2017

Get All File in Folder Using JSOM

function ViewAllFiles()
{
var context = new SP.ClientContext.get_current();
var web = context.get_web();
var list = web.get_lists().getByTitle('NGO-Document');
var query = SP.CamlQuery.createAllItemsQuery();
query.set_folderServerRelativeUrl('/NGO-Document/NGOFolder');
allItems = list.getItems(query);
context.load(allItems, 'Include(Title, ContentType, File)');
context.executeQueryAsync(Function.createDelegate(this, this.success),   Function.createDelegate(this, this.failed));
}
 
function success()
{
debugger;
  var fileUrls = "";
  var ListEnumerator = this.allItems.getEnumerator();
   while(ListEnumerator.moveNext())
   {
    var currentItem = ListEnumerator.get_current();
    var _contentType = currentItem.get_contentType();
     if(_contentType.get_name() != "Folder")
       {
        var File = currentItem.get_file();
        if(File != null)
          {
           fileUrls += File.get_serverRelativeUrl() + '\n';
          }
       }
   }
  alert(fileUrls);
}
function failed(sender, args) {
  alert("failed. Message:" + args.get_message());
}
 

No comments:

Post a Comment