Share via

Get all the files and folders in the library of SharePoint Online site with one request

Kelly 81 Reputation points
2021-11-22T14:30:30.107+00:00

I am getting the files of a folder using this: https://learn.microsoft.com/en-us/graph/api/driveitem-list-children?view=graph-rest-1.0&tabs=http. This works fine for me.

But the endpoint can only get the files in the first level, it cannot get the files in the subfolders. I need to loop through all the folders to get the files, this is not an option.

My library is like this: foler ->subfolder ->sub subfolder ->files. All the folders have files and subfolders. I just want to get all the files using one request. Is it possible?

Kelly

Microsoft 365 and Office | SharePoint | Development
Microsoft Security | Microsoft Graph
0 comments No comments

Answer accepted by question author

MichaelHan-MSFT 18,136 Reputation points
2021-11-23T05:39:55.84+00:00

Hi @Kelly ,

As a workaround, you could get all the list items in the library using this endpoint:

https://graph.microsoft.com/v1.0/sites/{site-id}/lists/{list-id}/items?$expand=driveItem  

In the response, it would contaion all the files and folders in the specifice library.


If the answer is helpful, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.


Was this answer helpful?

0 comments No comments

0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.