Phil Salomon
Phil Salomon

Reputation: 175

Retrieve a list of folders in SharePoint using Microsoft Graph

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

Upvotes: 0

Views: 2108

Answers (1)

Carl Zhao
Carl Zhao

Reputation: 9549

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

Upvotes: 0

Related Questions