簡體   English   中英

使用 Microsoft Graph API 獲取文件夾中的所有文件

[英]Get all Files in a folder using 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 的新手,不知道哪里出錯了。 任何幫助將不勝感激。

如文檔中所述: https://docs.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

您的示例要根據路徑列出孩子:

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

您如何將其轉換為使用 csharp 在服務器站點上使用 GraphServiceClient?

例如,我正在嘗試這樣的事情:

var driveItems = await graphClient.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”子文件夾中的文件列表:

在此處輸入圖像描述

參考:

在 Microsoft Graph 中處理文件

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM