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

时间:2019-10-17 20:35:08

标签: c# sharepoint microsoft-graph microsoft-graph-sdks

ListItem中的

driveItem在文档库中始终为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();
}

2 个答案:

答案 0 :(得分:0)

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

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

答案 1 :(得分:0)

您需要将ListItem显式添加到DriveItem

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