Creating a file with PutAsync (ToPutRequestInformation) is creating missing folders, how do I stop this?
Mark Leavesley
11
Reputation points
If I try and upload a file to a folder that doesn't exist, the below code will create the missing folder. This is undesirable to say in the least nor can I see that it is documented behaviour.
How do I stop this happening?
var requestInformation = _graphClient
.Drives[sourceList.Drive.Id]
.Root
.ItemWithPath(siteRelativePath + "/" + fileName)
.Content
.ToPutRequestInformation(stream);
requestInformation.URI = new Uri(requestInformation.URI.OriginalString + "?@microsoft.graph.conflictBehavior=" + conflictBehaviorValue);
var di = await _graphClient.RequestAdapter.SendAsync(requestInformation, DriveItem.CreateFromDiscriminatorValue);
I can do a check for the folder first, but it slows down the process quite a lot:
var di = await _graphClient.Drives[sourceList.Drive!.Id].Root.ItemWithPath(sanitizedSiteRelativePath.ToString()).GetAsync();
Microsoft Graph
Microsoft Graph
A Microsoft programmability model that exposes REST APIs and client libraries to access data on Microsoft 365 services.
13,607 questions
1 answer
Sort by: Most helpful
-
Deleted
This answer has been deleted due to a violation of our Code of Conduct. The answer was manually reported or identified through automated detection before action was taken. Please refer to our Code of Conduct for more information.
Comments have been turned off. Learn more