使用 Microsoft Graph API 获取文件夹中的所有文件

Gir*_*ran 5 sharepoint microsoft-graph-files power-automate microsoft-graph-api

要求 - 需要访问文档库中的特定文件

文件路径 - 主机名/站点/站点名/共享文档/Folder1/File1

我尝试过这些

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

  • 获取该站点中的所有文档库

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

尝试上面的错误,错误的请求。

我是 MS Graph 的新手,不知道哪里出了问题。任何帮助将不胜感激。

小智 10

如文档中所述:https://learn.microsoft.com/en-us/graph/api/driveitem-list-children,如果您已经拥有驱动器 ID,则只需发出以下请求即可列出子项:

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

或者,如果您想列出子文件夹中的项目:

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

根据路径列出子项:

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

在你的情况下:

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


小智 5

根据路径列出子项的示例:

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

如何将其转换为使用 csharp 在服务器站点上使用 GraphServiceClient?

例如,我正在尝试这样的事情:

vardriveItems=awaitgraphClient.Sites["mypersonalteamsite.sharepoint.com"].Drive.Root.{我还需要做什么来指定路径?}.{Children?}.Request().GetAsync();

我知道我在https://mypersonalteamsite.sharepoint.com/IT下有文件和文件夹 ,我想使用路径获取这些文件和文件夹。

因此,如果我需要获取子文件夹中的文件,我可以使用路径。例如。https://mypersonalteamsite.sharepoint.com/IT/mysubfolder/mysubsubfolder2/file.txt

另外,如果我需要获取文件和文件夹的列表,我只是喜欢使用路径,例如。https://mypersonalteamsite.sharepoint.com/IT/mysubfolder/mysubsubfolder2/ *