简体   繁体   English

如何使用 Microsoft Graph 获取 DriveItem 上的 Sharepoint ListItem

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

ListItem of a driveItem is in a document library is always null . driveItemListItem在文档库中始终为null How to get custom fields of file?如何获取文件的自定义字段? I want to build a function to get the content stream and fields of file.我想构建一个 function 来获取内容 stream 和文件字段。

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();
}

You need to add ListItem explicitly to DriveItem您需要将 ListItem 显式添加到 DriveItem

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

The sharepointIds property of the drive item should contain the information you need to read the list item.驱动器项的sharepointIds属性应包含读取列表项所需的信息。

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM