首页 > 解决方案 > MS Graph 客户端库,删除 UploadSession

问题描述

使用 Microsoft Graph 客户端库 1.21.0,我找到了如何创建上传会话的示例。但我找不到如何使用库删除上传会话的示例。请指教。

    private UploadSession CreateUploadSession(string relativeName)
    {
        UploadSession uploadSession = null;

        try
        {
            uploadSession = Task.Run(() => Client.Drives[DriveId].Items[RootPathId]
                .ItemWithPath(relativeName)
                .CreateUploadSession()
                .Request()
                .PostAsync())
                .Result;
        }
        catch (AggregateException ae)
        {
            ae.Handle(ex =>
            {
                if (ex is ServiceException && ((ServiceException)ex).IsMatch(GraphErrorCode.NameAlreadyExists.ToString()))
                {
                    // An upload session already exists.  Delete it and try again.

                    return true;
                }
                else
                {
                    return false;
                }
            });
        }

        return uploadSession;
    }

标签: .net

解决方案


推荐阅读