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

Viewed 1937

ListItem of a driveItem is in a document library is always null. How to get custom fields of file? I want to build a function to get the content stream and fields of file.

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 Answers

You need to add ListItem explicitly to DriveItem

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