Warm tip: This article is reproduced from stackoverflow.com, please click
c# microsoft-graph microsoft-graph-sdks

How to get informations of a drive inside another ms graph sdk

发布于 2020-03-28 23:16:54

I am copying a file from a drive to another drive using ms graph sdk in c#.

To copy into a drive i have to get the parentReference of the destination drive.

I use the code below :

var parentref = graphClient
  .Sites[IdGestDoc]
  .Drives[DriveId]
  .Root
  .Request()
  .GetAsync()
  .Result;

var parentReference = new ItemReference
{
  DriveId = DriveId,
  Id = parentref.Id
};

It is working well when I try it using the Drive ID of the root drive.

But when i try to use this line with the Drive ID of a subdrive, it returns the following error message :

The provided drive id appears to be malformed, or does not represent a valid drive.

I thought I could use the code for any drive ID, but it appears to be not true.

So how could i get the same information for the subdrives as the root drive?

For more details, the Id of the root drive looks like this :

b!07TT1TT6TTOI-xYElkDOj9a5a_hmu6RDt0mpVQfH3RFpCR1wxODCRpss4Xq4g75t

On the other hand, the Id of a subdrive looks like this :

01QVACJXG2T46MR734INA24SEQ3LZYRIZR

It is pretty obvious that there are two different types of IDs, so i am getting the error message. That's why i am asking how to get the information to fill the parent reference object for the copy of a file is successful?

Questioner
Tristan Sébillet
Viewed
73
Tristan Sébillet 2020-01-31 23:31

I knew that in order to copy a file to a destination drive, the ParentReference needed DriveId and Id to be filled.

What i did not knew was that the DriveId was the Id of the root Drive.

So in order to make the copy successfull, the ParentReference object has to look like the following :

    var parentReference = new ItemReference
    {
        DriveId = DriveId, //root drive Id => b!07TT1TT6TTOI-xYElkDOj9a5a_hmu6RDt0mpVQfH3RFpCR1wxODCRpss4Xq4g75t
        Id = parentref.Id //destination drive Id => 01QVACJXG2T46MR734INA24SEQ3LZYRIZR
    };

you get the parentReference of a subDrive using this endpoint :

/sites/{site-id}/drive/items/{item-id}