要求 - 需要访问文档库中的特定文件
文件路径 - 主机名/站点/站点名/共享文档/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 的新手,不确定我哪里出错了。任何帮助将不胜感激。
如文档中所述: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
根据路径列出子项的示例:
获取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/*
如果您想列出存储在站点默认共享文档库中的子文件夹内的所有文件,请使用此端点:
https://graph.microsoft.com/v1.0/sites/siteId/drive/root:/Folder1:/children
这是端点返回的 Web url,获取“Folder1”子文件夹中的文件列表:
参考:
您不能只列出根目录中的所有子项,因为它包含所有内容(函数、文件、文件夹、注释、枚举等),如果项目超过 200 个,您将无法获得列表,将获得下一个链接来解析它们。另外,你想要一个答案,对吧?
根据您的要求,最好的查询是使用根路径。
/drives/{drive-id}/root:/{path-relative-to-root}:/children
您可以从此处的 MS Graph 文档中获取该信息 - https://learn.microsoft.com/en-us/graph/api/driveitem-list-children?view=graph-rest-1.0&tabs=http
希望有帮助,彼得