最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

azure - How to create upload session for SharePoint file via MsGraph SDK for C#? - Stack Overflow

programmeradmin5浏览0评论

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
Add a comment  | 

1 Answer 1

Reset to default 1

The 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);
发布评论

评论列表(0)

  1. 暂无评论