如何使用 Microsoft Graph API c# SDK 在 DriveItem 上获取 Sharepoint ListItem

How to get Sharepoint ListItem on DriveItem with Microsoft Graph API c# SDK

ListItemdriveItem 在文档库中总是 null。如何获取文件的自定义字段?我想构建一个函数来获取文件的内容流和字段。

var client = GetAuthenticatedClient();
var driveItems = await client.Sites[siteId].Drives[driveId].Root.Children.Request().GetAsync();
foreach (var driveItem in driveItems)
{
    //ListItem is always null
    if (driveItem.ListItem!=null)
    {
        //get columns
        var blabla = driveItem.ListItem.Fields.AdditionalData["blabla"];
    }

    //SharepointIds is always null too 
    if (driveItem.SharepointIds != null)
    {

    }

    //get file to download
    var file = await client.Drives[driveId].Items[driveItem.Id].Content.Request().GetAsync();
}

驱动器项的sharepointIds属性应该包含您阅读列表项所需的信息。

https://docs.microsoft.com/en-us/graph/api/resources/sharepointids?view=graph-rest-1.0

您需要将 ListItem 显式添加到 DriveItem

var driveItems = await client.Sites[siteId].Drives[driveId].Root.Children.Request().Expand(item => item.ListItem).GetAsync();