I am trying to upload file to a SharePoint Site's shared folder using the following code:
var uploadSession = await _graphClient.Sites[siteId]
.Drives[driveId]
.Root
.ItemWithPath($"{folderPath}{info.Name}")
.CreateUploadSession()
.Request()
.PostAsync();
I got compile error:
'DriveItemRequestBuilder' does not contain a definition for 'Root' and no accessible extension method 'Root' accepting a first argument of type 'DriveItemRequestBuilder' could be found (are you missing a using directive or an assembly reference?)
I've also tried to use .Items["root"] instead of .Root, same error
Further thoughts:
DriveItemRequestBuilder
class, one in the namespace Microsoft.Graph.Drives.Item.DriveItemRequestBuilder
this is for the personal folder like var uploadSession = await _graphClient.Drives[myDrive?.Id]
and a completely different in Microsoft.Graph.Sites.Item.Drives.Item.DriveItemRequestBuilder
this is for _graphClient.Sites[siteId].Drive...
this is for the Sites, and what I need.Literally all examples are either for the legacy version, or the personal folder...
Code for SDK v5 is autogenerated and generating of C# code for some paths like /sites/{siteId}/drives/{driveId}/items/*
is restricted.
With a knowledge of driveId
, you can directly call /drives/{driveId}
to access the root folder and an item by a path
var uploadSession = await _graphClient
.Drives[driveId]
.Root
.ItemWithPath($"{folderPath}{info.Name}")
.CreateUploadSession
.PostAsync(new Microsoft.Graph.Drives.Item.Items.Item.CreateUploadSession.CreateUploadSessionPostRequestBody { });