1

I'm trying to list all files with all properties/fields (ListItemAllFields) for the given server relative path.

Problems:

  1. I'm using this method to list files:
 https://<sub-domain>.sharepoint.com/sites/<site-name>/_api/web/GetFolderByServerRelativeUrl('/sites/<site-name>/Shared Documents/folder path')/Files

This method list files in for given folder. I want to list all files for the given folder and all sub-folder in it. Is it possible with a single API call?

  1. If we want to list all fields for a given file, we use ListItemAllFields:
https://<subdomain>.sharepoint.com/sites/<sitename>/_api/Web/GetFileByServerRelativePath(decodedurl='/sites/<site-name>/Shared Documents/file path')/ListItemAllFields

Can't we combine this with the first method I mentioned above? I don't want to make API calls for each and every file.

1 Answer 1

0

Use REST API endpoint in this format:

_api/web/GetFolderByServerRelativeUrl('/sites/<site-name>/Shared Documents/folder path')/Files?$expand=ListItemAllFields

Similar thread: How to get all properties of a Site Page using REST API?


Try using REST endpoint in below format to get all files & folders inside specific folder:

https://server/_api/Web/GetFolderByServerRelativeUrl(<folder url>)?$expand=Folders,Files

More information at:

  1. Get all Files and Folders in one call
  2. Get all SharePoint Document Library Files and Folders at a ServerRelativeUrl in One REST Call
3
  • Hey! Thank you for your response. I also want to list all files in folders and subfolders. Shared Documents/folder1/folder2/folder3. If I give the folder path as a Shared Documents/folder1, I also want files inside folder2 and folder3.
    – Dhruvin
    Mar 3 at 5:40
  • Check links in updated answer. Hope it helps! Mar 3 at 6:40
  • 1
    Hey! Thanks For your help. I have looked into the document. In my case, folder depth can be different. But no worries. I will implement a recursive approach. Again, Thanks for your help. Appreciated.
    – Dhruvin
    Mar 3 at 7:05

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.