Outdated Graph API example for uploading files to OneDrive

Bob Lan 0 Reputation points
2024-07-21T00:48:25.18+00:00
var driveItem = await serviceClient.Me.Drive.Root.ItemWithPath(itemPath).Content.Request().PutAsync<DriveItem>(stream);

https://video2.skills-academy.com/en-us/training/modules/msgraph-dotnet-core-manage-files/7-upload-user-files

The example code above is no longer working with Microsoft.Graph v5.*. Can you please update it?

I tried to update it; however Request() is not defined:

await serviceClient.Drives[oneDrive!.Id].Items["root"].ItemWithPath(itemPath).Content.Request().PutAsync<DriveItem>(fileStream);

This question is related to the following Learning Module

ASP.NET Core Training
ASP.NET Core Training
ASP.NET Core: A set of technologies in the .NET Framework for building web applications and XML web services.Training: Instruction to develop new skills.
21 questions
{count} votes

1 answer

Sort by: Most helpful
  1. Bob Lan 0 Reputation points
    2024-07-21T04:03:07.9866667+00:00

    The following code should work for small file:

    var oneDrive = await serviceClient!.Users[oneDriveUser].Drive.GetAsync();
    
    or
    
    var oneDrive = await serviceClient!.Me.Drive.GetAsync();
    
    then:
    
    await serviceClient.Drives[oneDrive!.Id].Items["root"].ItemWithPath(itemPath).Content.PutAsync(fileStream);
    
    
    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.