Outdated Graph API example for uploading files to OneDrive

Bob Lan 5 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://learn.microsoft.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.
25 questions
{count} votes

2 answers

Sort by: Most helpful
  1. Bob Lan 5 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);
    
    
    1 person found this answer helpful.
    0 comments No comments

  2. Pradeep M 3,840 Reputation points Microsoft Vendor
    2024-10-03T08:32:01.25+00:00

    Hi Bob Lan,

    Thanks for bringing this to our notice.

    Our team is aware of this issue and is actively working on a solution.

    In the meantime, we ask that you complete the Learning Paths without the exercise modules. We will provide updates as soon as we have more information.

    Thank you for your patience and understanding.

    1 person found this answer helpful.
    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.