An API that connects multiple Microsoft services, enabling data access and automation across platforms
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 Security | Microsoft Graph
Microsoft Security | Microsoft Graph
Sign in to answer