1

I'm trying to rewrite this code so that it will work with the version 5.0 of the Microsoft Graph .NET SDK:

private async static Task<DriveItem> UploadSmallFile(string driveId, string filePath, MemoryStream fileStream)
{
  var queryOptions = new List<QueryOption>()
  {
    new QueryOption("@microsoft.graph.conflictBehavior", "replace"),
  };

  DriveItem file = await GraphClient
    .Drives[driveId]
    .Root
    .ItemWithPath(filePath)
    .Content
    .Request(queryOptions)
    .PutAsync<DriveItem>(fileStream);
    return file;
}

The following code creates a file but does not return the DriveItem since the PutAsync as a void function (Task). I'm also unclear about how I can pass the conflictBehavior as "replace".

await GraphClient
.Drives[driveId]
.Root
.ItemWithPath(filePath)
.Content
.PutAsync(fileStream);

Any help is appriciated.

1 Answers1

1

I was facing the same issue in the version 5.0.0 and I make one extra call to get new drive item

var driveItem = await GraphClient.Drives[driveId].Root.ItemWithPath(filePath).GetAsync();

The issue with conflictBehavior is reported here

user2250152
  • 14,658
  • 4
  • 33
  • 57
  • Thanks for the good answer. It is unfortunate to have to make two request with the new "simple" api instead of just one before. I'm not seeing a solution to how I can pass the conflictBehavior data with the PutRequest in 5.0.0. I hope I don't have to make 3 requests to achieve what could be done with one in the older version. It would be great if you could add that code to the answer so it is complete. Thanks again. – Ásgeir Gunnar Stefánsson Mar 08 '23 at 20:24