0

I’m using the graph api from a c# app to access SharePoint. I need to get a list of all folders and sub folders. I have tried getting the drive item and then iterating through the children looking for folders and then recursively working through the list but it’s too slow.

I have also tried this end point

https://graph.microsoft.com/v1.0/sites/{site-id}/lists/{list-id}/items?$expand=fields&$filter=fields/ContentType eq 'Folder'

With this header Prefer: HonorNonIndexedQueriesWarningMayFailRandomly

But it returned that the query would consume too many resources.

Is there a way to A. Get the folders more efficiently or B. Do a search to return folders or C. Only list folders in the children endpoint

CBroe
  • 91,630
  • 14
  • 92
  • 150
Phil Salomon
  • 163
  • 2
  • 9

1 Answers1

0

You can call this endpoint to get all files and folders in the specific library:

https://graph.microsoft.com/v1.0/sites/{site-id}/lists/{list-id}/items?$expand=driveItem
Carl Zhao
  • 8,543
  • 2
  • 11
  • 19
  • Trouble is there are thousands of items to go through and only relatively few folders. Is it possible to just list the folders instead of all the items – Phil Salomon Feb 07 '23 at 23:58
  • Yes, of course, you just need to do a simple filtering: `https://graph.microsoft.com/v1.0/sites/{site id}/lists/{list id}/items?$select=name,contentType,webUrl,id&$expand=driveItem,fields&$filter=fields/ContentType eq 'Folder' Prefer: allowthrottleablequeries ` – Carl Zhao Feb 08 '23 at 08:27
  • Im receiving the following exception, The Request is Unprocessable because it uses too many resources – Phil Salomon Feb 09 '23 at 11:25
  • It might be I need to create an index on the ContentType column? – Phil Salomon Feb 10 '23 at 07:37