private async Task <OneDriveStorageFile> CreateFileInternalAsync(string desiredName, CreationCollisionOption options = CreationCollisionOption.FailIfExists, IRandomAccessStream content = null, CancellationToken cancellationToken = default(CancellationToken)) { Stream streamContent = null; if (string.IsNullOrEmpty(desiredName)) { throw new ArgumentNullException(nameof(desiredName)); } if (content == null) { // Because OneDrive (Not OneDrive For business) don't allow to create a file with no content // Put a single byte, then the caller can call Item.WriteAsync() to put the real content in the file byte[] buffer = new byte[1]; buffer[0] = 0x00; streamContent = new MemoryStream(buffer); } else { if (content.Size > OneDriveUploadConstants.SimpleUploadMaxSize) { throw new ServiceException(new Error { Message = "The file size cannot exceed 4MB, use UploadFileAsync instead ", Code = "MaxSizeExceeded", ThrowSite = "Windows Community Toolkit" }); } streamContent = content.AsStreamForRead(); } var childrenRequest = ((IDriveItemRequestBuilder)_oneDriveStorageFolder.RequestBuilder).Children.Request(); string requestUri = $"{childrenRequest.RequestUrl}/{desiredName}/[email protected]={OneDriveHelper.TransformCollisionOptionToConflictBehavior(options.ToString())}"; HttpRequestMessage request = new HttpRequestMessage(HttpMethod.Put, requestUri) { Content = new StreamContent(streamContent) }; var createdFile = await((IGraphServiceClient)_service.Provider.GraphProvider).SendAuthenticatedRequestAsync(request, cancellationToken); return(_oneDriveStorageFolder.InitializeOneDriveStorageFile(createdFile)); }