簡體   English   中英

如何使用Microsoft Graph API通過自定義列值查找SharePoint文檔

[英]How to find SharePoint documents by custom column value using Microsoft Graph API

通過Office 365帳戶在SharePoint Online網站中,我向文檔中添加了“ CustomerId”列。 我想在C#中找到CustomerId為102的所有文檔(不是在JavaScript中)。

到目前為止,我已經能夠將所有文件保存在一個文件夾下

var files = graphClient.Sites[siteId].Drive.Items[driveItemId]
            .Children.Request().GetAsync().Result;

或在“圖形資源管理器”中查看相同的結果https://graph.microsoft.com/v1.0/sites/{siteId}/drive/items/{driveItemId}/children

但是我還沒有弄清楚使用C#或Graph Explorer中的自定義列過濾條件獲取所有文檔(driveIems)的正確語法。 我嘗試過的事情的示例:

在C#中

var files = graphClient.Sites[siteId].Drive.Items[driveItemId]
            .Search("fields/CustomerId eq 102").Request().GetAsync().Result;

在圖形資源管理器中https://graph.microsoft.com/v1.0/sites/{siteId}/drive/items/{driveItemId}/search(q='CustomerId eq 102')

希望有人可以幫助我。

更新:
以前我從以下位置獲得driveItemId

var customerFolder = graphClient.Sites[siteId].Drive.Root
    .ItemWithPath("CustomerGroup/IndustryGroup").Request().GetAsync().Result;
string driveItemId = customerFolder.Id;

我看到我可以得到一個ListItem

var customerFolder = graphClient.Sites[siteId].Drive.Root
    .ItemWithPath("CustomerGroup/IndustryGroup").Request()
    .Expand(d => d.ListItem).GetAsync().Result;

但是我只從customerFolder.ListItem.Id中找到列表ID為“ 4”

如何獲得列表ID,以便可以在graphClient.Sites [siteId] .Lists [listId]中使用它?

我建議利用以下查詢:

https://graph.microsoft.com/v1.0/sites/{site-id}/lists/{list-id}/items?filter=fields/CustomerId eq 123&expand=driveItem

說明:

  • 通過filter查詢選項filter列表中的項目
  • 通過expand查詢選項返回列表項的相關驅動器項

這是msgraph-sdk-dotnet的示例:

var request = await graphClient.Sites[siteId].Lists[listId].Items.Request().Filter("fields/CustomerId eq 123").Expand(item => item.DriveItem).GetAsync();
foreach (var item in request)
{
    Console.WriteLine(item.DriveItem.WebUrl);
}

更新

可以像下面這樣檢索驅動器的基礎文檔庫列表 (及其屬性):

var list = await graphClient.Sites[siteId].Drive.List.Request().GetAsync();
Console.WriteLine(list.Id);  //gives SharePoint List Id

注意: https://graph.microsoft.com/beta/sites/{site-id}/drive : https://graph.microsoft.com/beta/sites/{site-id}/drive {site-id}/ drive端點返回此站點的默認驅動器 (文檔庫)

參考

在Microsoft Graph中使用SharePoint網站

暫無
暫無

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

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