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.

Ganesh Sanap - MVP
  • 44,918
  • 21
  • 30
  • 61
Dhruvin
  • 13
  • 4

1 Answers1

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
Ganesh Sanap - MVP
  • 44,918
  • 21
  • 30
  • 61
  • 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 03 '23 at 05:40
  • Check links in updated answer. Hope it helps! – Ganesh Sanap - MVP Mar 03 '23 at 06: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 03 '23 at 07:05