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

  • Question

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

    Thursday, October 17, 2019 8:52 PM

All replies

  • Hi

    What field do you want to fetch, if it is a custom field, maybe you need to get it via ListItem but not DriveItem.

    For more info please check below link.

    Get a DriveItem.

    Get a ListItem.


    Justin Liu Office Apps & Services MVP, MCSE
    Senior Software Engineer
    Learn Microsoft 365 from Microsoft DOCs now!
    Please Vote and Mark as Answer if it helps you.

    Friday, October 18, 2019 3:19 AM
  • I can get it via ListItem but i couldn`t find the relationship between ListItem and DriveItem. SharepointIds are also null. I need to get the driveitem (file content stream) with custom fields on it.

    When i get ListItem, i can't reach DriveItem on ListItem, it's also null. There should be a correlated property between them.


    • Edited by ozgec Friday, October 18, 2019 2:02 PM
    Friday, October 18, 2019 2:02 PM
  • Have you tried to use {itemid} to get the object?

    Justin Liu Office Apps & Services MVP, MCSE
    Senior Software Engineer
    Learn Microsoft 365 from Microsoft DOCs now!
    Please Vote and Mark as Answer if it helps you.

    Monday, October 21, 2019 4:59 AM
  • yes but itemid of driveitem and listitem is diffent so it didn't work.
    Monday, October 21, 2019 6:01 PM