3

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();
}
Anna
  • 2,988
  • 3
  • 15
  • 29
J. Y.
  • 35
  • 5

2 Answers2

2

You need to add ListItem explicitly to DriveItem

var driveItems = await client.Sites[siteId].Drives[driveId].Root.Children.Request().Expand(item => item.ListItem).GetAsync();
Gander
  • 1,854
  • 1
  • 23
  • 30
0

The sharepointIds property of the drive item should contain the information you need to read the list item.

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

Paul Schaeflein
  • 607
  • 3
  • 11