简体   繁体   中英

Get all Files in a folder using Microsoft Graph API

Requirement - Need to access a particular File within a Document Library

File Path - host-name/sites/sitename/Shared Documents/Folder1/File1

I tried with these

https://graph.microsoft.com/v1.0/sites/{host-name}/sites/{site-id}:/drives

  • Got all the Document Library in that site

https://graph.microsoft.com/v1.0/sites/{host-name}/sites/{site-id}:/drives/{drive-id}/root/children

Tried with the above getting error, Bad request.

I am new to MS Graph, Not sure where I am going wrong. Any help will be highly appreciated.

As specified in the documentation: https://docs.microsoft.com/en-us/graph/api/driveitem-list-children , if you already have the drive-id than you can just make the following request to list the children:

GET https://graph.microsoft.com/v1.0/drives/{drive-id}/items/root/children

Or if you want to list the items in a sub-folder:

GET https://graph.microsoft.com/v1.0/drives/{drive-id}/items/{item-id}/children

To list the children based on the Path:

GET https://graph.microsoft.com/v1.0/drives/{drive-id}/root:/{path-relative-to-root}:/children

In your case:

GET https://graph.microsoft.com/v1.0/drives/{drive-id}/root:/Shared Documents/Folder1/File1:/children

Your example to To list the children based on the Path:

GET https://graph.microsoft.com/v1.0/drives/{drive-id}/root:/{path-relative-to-root}:/children

How do you translate this to using GraphServiceClient on the server site using csharp?

For example, I am trying something like this:

var driveItems = await graphClient.Sites["mypersonalteamsite.sharepoint.com"].Drive.Root.{what else do I need to do specify the path?}.{Children?}.Request().GetAsync();

I know I have files and folders under https://mypersonalteamsite.sharepoint.com/IT I want to get these using path.

So if I need to get file in the subfolder I can just use the path. eg. https://mypersonalteamsite.sharepoint.com/IT/mysubfolder/mysubsubfolder2/file.txt

Also if I need to get list of files & folders, I just like to use the path eg. https://mypersonalteamsite.sharepoint.com/IT/mysubfolder/mysubsubfolder2/ *

If you want to list all files within a subfolder which is stored in the default Shared Document library in a site, please use this endpoint:

https://graph.microsoft.com/v1.0/sites/siteId/drive/root:/Folder1:/children

This is the returned web url for the endpoint, get the files list within "Folder1" subfolder:

在此处输入图像描述

Reference:

Working with files in Microsoft Graph

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM