I'm using following code through the Microsoft Graph API dot.net sdk
using (Stream fileStream = file.InputStream)
{
DriveItem uploadedFile = await graphClient
.Drives[DRIVE_ID]
.Root.ItemWithPath($"{root}{relative}{file.FileName}")
.Content.Request()
.PutAsync<DriveItem>(fileStream);
}
to upload a simple file to OneDrive. Is it possible to prevent the file upload if the file already exists?
Update
The Microsoft Graph Documentation has been updated here a snippet from it:
Request body
https://developer.microsoft.com/en-us/graph/docs/api-reference/v1.0/api/item_createuploadsession
No request body is required. However, you can specify a request body to provide additional data about the file being uploaded. For example, to control the behavior if the filename is already taken, you can specify the conflict behavior property in the body of the request.
{
"item": {
"@microsoft.graph.conflictBehavior": "rename"
}
}
Unfortunately no. In order to prevent file override (which also creates a new version) you have to first check if the file with the path already exists. You can do that programmatically by listing parent folder contents and checking by filename.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With