According to the documentation, it's possible to create upload session for large file in SharePoint's Documentation Library if you know list id and item id:
POST /drives/{driveId}/items/{itemId}/createUploadSession
or
POST /sites/{siteId}/drive/items/{itemId}/createUploadSession
In MsGraph SDK for C# v4.x it was possible to execute
var session = await sessionClient.Sites[GraphSiteId].Lists[list.ID]
.Items[file.ID]
.DriveItem
.CreateUploadSession()
.Request()
.PostAsync();
But MsGraph SDK API has been changed in v5.x and i cannot find how to do the same but in recent SDK.
Could you please help with?
P.S.: There are no problems with uploading code via LargeFileUploadTask<> but i need upload session object to execute it.
According to the documentation, it's possible to create upload session for large file in SharePoint's Documentation Library if you know list id and item id:
POST /drives/{driveId}/items/{itemId}/createUploadSession
or
POST /sites/{siteId}/drive/items/{itemId}/createUploadSession
In MsGraph SDK for C# v4.x it was possible to execute
var session = await sessionClient.Sites[GraphSiteId].Lists[list.ID]
.Items[file.ID]
.DriveItem
.CreateUploadSession()
.Request()
.PostAsync();
But MsGraph SDK API has been changed in v5.x and i cannot find how to do the same but in recent SDK.
Could you please help with?
P.S.: There are no problems with uploading code via LargeFileUploadTask<> but i need upload session object to execute it.
Share Improve this question edited Mar 17 at 17:55 23W asked Mar 17 at 17:50 23W23W 1,54022 silver badges47 bronze badges 3- So you want to upload file to sharepoint with itemid known? – Rukmini Commented Mar 18 at 5:59
- @Rukmini, yes you're right. and it was possible to do it in old MsGraph SKD 4.x. i don't know how to do it with updated API of MsGraph SKD 5.x – 23W Commented Mar 18 at 6:52
- Based on the MsDoc you can use these learn.microsoft/en-us/graph/api/… queries only – Rukmini Commented Mar 18 at 6:54
1 Answer
Reset to default 1The SDK v5 doesn't generate code for all endpoints, so you need to get driveItem
and then create upload session
var driveItem = await sessionClient.Sites[GraphSiteId]
.Lists[list.ID]
.Items[file.ID]
.DriveItem.GetAsync();
var uploadSessionBody = new Microsoft.Graph.Drives.Item.Items.Item.CreateUploadSession.CreateUploadSessionPostRequestBody
{
Item = new DriveItemUploadableProperties
{
Name = "file.txt",
AdditionalData = new Dictionary<string, object>
{
{ "@microsoft.graph.conflictBehavior", "replace" }
}
}
};
var uploadSession = await sessionClient
.Drives[driveItem.ParentReference.DriveId]
.Items[driveItem.Id]
.CreateUploadSession
.PostAsync(uploadSessionBody);