How to Get List of folders and files in SharePoint Document library using REST API in SharePoint online/Office 365?

Hello SharePointers,

Below is the REST API snippet to find folders and files inside the folder url of a sharepoint document library.

var folderUrl = ‘myfolder/2016’;
var url = _spPageContextInfo.webServerRelativeUrl + “/_api/Web/GetFolderByServerRelativeUrl(‘” + folderUrl + “‘)?$expand=Folders,Files”;

$.getJSON(url,function(data,status,xhr){

for(var i = 0; i < data.Files.length;i++){
console.log(data.Files[i].Name);
}

for(var i = 0; i < data.Folders.length;i++){
console.log(data.Folders[i].Name);
}
});

Happy SharePointing 🙂

Leave a Reply

Your email address will not be published.