首页 > 解决方案 > 如果存在 Sharepoint,则创建文件夹

问题描述

我有以下代码,直到最近才运行良好

private async Task<DriveItem> CreateFolderIfNotExists(GraphServiceClient graphClient, string driveId, string folderName)
    {
        try
        {
            var driveItem = new DriveItem
            {
                Name = folderName,
                Folder = new Folder(),
                AdditionalData = new Dictionary<string, object>()
                {
                    { "@microsoft.graph.conflictBehavior", "fail" }
                }
            };

            return await graphClient.Drives[driveId].Root.Children
                .Request()
                .AddAsync(driveItem);
        }
        catch (ServiceException exception)
        {
            if (exception.StatusCode != HttpStatusCode.Conflict)
            {
                throw;
            }

            return await this.GetFolderItem(graphClient, driveId, folderName);
        }
    }

突然间,我们得到了这个:

System.NullReferenceException:对象引用未设置为对象的实例。在 Microsoft.Graph.HttpProvider.SendAsync(HttpRequestMessage request, HttpCompletionOption completionOption, CancellationToken cancelToken) 在 Microsoft.Graph.BaseRequest.SendRequestAsync(Object serializableObject, CancellationToken cancellationToken, HttpCompletionOption completionOption) 在 Microsoft.Graph.BaseRequest.SendAsync[T](Object serializableObject ,xyz\Client\SharePointClient.cs 中 xyz.CreateFolderIfNotExists(GraphServiceClient graphClient, String driveId, String folderName) 处的 CancellationTokencancellationToken, HttpCompletionOption completionOption):xyz.Client.SharePointClient.CopyLegacyFile (String fileId, String destination, String newFileName) 处的第 63 行字符串 documentLibraryId) xyz\Client\SharePointClient.cs:

知道发生了什么吗?没有代码推送导致这种情况。

标签: c#sharepointmicrosoft-graph-api

解决方案


推荐阅读