msgraph-sdk-dotnet
msgraph-sdk-dotnet copied to clipboard
Can't create empty file (e.g. on OneDrive) when using Microsoft.Graph v5.44.0
I am updating my app to use Microsoft.Graph v5.44.0. Apparently it doesn't seem to be possible to create an empty file on OneDrive. In v3.21.0 this works successfully as follows (srcStream has zero-length):
// Create file (of zero-length)
var newDriveItem = _graphClient.Me.Drive.Root.ItemWithPath(destinationFilePathName).Content
.Request()
.PutAsync<DriveItem>(srcStream)
.GetAwaiter()
.GetResult();
in v5 this (I think) has to be done as follows:
// Create file (of zero-length)
var newDriveItem = _graphClient.Drives[_driveId].Root.ItemWithPath(destinationFilePathName).Content
.PutAsync(srcStream)
.GetAwaiter()
.GetResult();
The ODataError.Error returned is: Code: BadRequest Message: Entity only allows writes with a JSON Content-Type header.
Desktop
- OS: Windows 11
- App: WinUI/WinAppSDK desktop app
Did some further tests and can report that the error occurs starting with v5.42. On v5.41 no error occurs and the file is successfully created.
See #2335