Hi
Could you please provide a sample code on How to upload small files in sharepoint using C# SDK version Version="5.4.0". The examples I find mostly based on old version of sdks. in the below code I dont seemed to find Request() method on content object.
GraphServiceClient graphClient = new GraphServiceClient( authProvider );
using var stream = new System.IO.MemoryStream(Encoding.UTF8.GetBytes(@"The contents of the file goes here."));
await graphClient.Me.Drive.Items["{driveItem-id}"].Content
.Request()
.PutAsync<DriveItem>(stream);
not sure If I am missing additional nuget package. ![GraphApi](https://learn-attachment.microsoft.com/api/attachments/818e3bd9-01b1-4beb-a72e-ad50f5db9f80?platform=QnA)
I am anyway have written following code which uploads empty file without any content.
public async Task<string> UploadNewFile(string driveId, string filePath, IFormFile file,
CancellationToken cancellationToken)
{
using var mst = new MemoryStream();
file.CopyTo(mst);
await _adekGraph.graphServiceClient.Drives[driveId]
.Root
.ItemWithPath(file.FileName)
.Content
.PutAsync(mst, cancellationToken: cancellationToken);
return "file uploaded";
}
This method is inside a service configured in Program.cs. I am using .net 7.
Thanks for the help.