コード例 #1
0
        private async Task <OneDriveStorageFolder> CreateFolderInternalAsync(string desiredName, CreationCollisionOption options = CreationCollisionOption.FailIfExists, CancellationToken cancellationToken = default(CancellationToken))
        {
            if (string.IsNullOrEmpty(desiredName))
            {
                throw new ArgumentNullException(nameof(desiredName));
            }

            var childrenRequest = ((IDriveItemRequestBuilder)_oneDriveStorageFolder.RequestBuilder).Children.Request();
            var requestUri      = childrenRequest.RequestUrl;

            HttpRequestMessage request = new HttpRequestMessage(HttpMethod.Post, requestUri);
            DriveItem          item    = new DriveItem {
                Name = desiredName, Folder = new Graph.Folder {
                }
            };

            item.AdditionalData = new Dictionary <string, object>();
            item.AdditionalData.Add(new KeyValuePair <string, object>("@microsoft.graph.conflictBehavior", OneDriveHelper.TransformCollisionOptionToConflictBehavior(options.ToString())));

            var jsonOptions = JsonConvert.SerializeObject(item);

            request.Content = new StringContent(jsonOptions, Encoding.UTF8, "application/json");

            var createdFolder = await((IGraphServiceClient)_service.Provider.GraphProvider).SendAuthenticatedRequestAsync(request, cancellationToken).ConfigureAwait(false);

            return(_oneDriveStorageFolder.InitializeOneDriveStorageFolder(createdFolder));
        }