3

The newly added DriveItem object returns the listItem field as null, which means that the relationship between DriveItem and ListItem offered by Graph Api cannot be used.

I created new DriveItem:

var driveItemResult= await CreateGraphClient().Groups[_options.GroupId].Sites[_options.SiteId]
                        .Drives[_driveOptions.DriveId]
                        .Root
                        .Children
                        .Request()
                        .AddAsync(driveItem).ConfigureAwait(false);

Now I would like to update custom columns in it. I know this is possible if you get driveItem as listItem. So I would like to do this:

var listItem= await CreateGraphClient().Groups[_options.GroupId].Sites[_options.SiteId]
                        .Lists[_listOptions.ListTitle]
                        .Items[driveItemResultId]
                        .Request()
                        .AddAsync(driveItem).ConfigureAwait(false);

But driveItemResult.Id returns Guid. I need Id as number to take Item from list. And driveItem has property listItem. So I thought I can get correct id if I take driveItem.ListItem.Id but driveItem.ListItem is always null.

Do you know what could caused this behavior or how to get correct id?

3
  • Can you please provide more details of your requirements? Commented Dec 9, 2019 at 5:24
  • Please add what you are trying to do..a code snippet will help.. Commented Dec 9, 2019 at 5:46
  • I added part with code. I will be grateful for help.
    – Iwoo
    Commented Dec 9, 2019 at 12:57

1 Answer 1

2

You can get the list item through below code:

CreateGraphClient().Groups[_options.GroupId].Sites[_options.SiteId]
                    .Drives[_driveOptions.DriveId]
                    .Items[driveitemid]
                    .ListItem
                    .Request().GetAsync()

Listitem is a expand property of driveitem, by default it has not been initialized. so we need to request it again.

BR

1
  • Thank you for this question and answer. I had exactly the same issue and this was a life saver :)
    – njames
    Commented Jan 23, 2023 at 7:03

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.