问题
I'm working on a C# project with these requirements:
- Create a Folder if it doesn't exits
- Check if the already exists, if it exists increment the file name.
From Onedrive API documentation Create a new Folder in OneDrive, it says that setting @microsoft.graph.conflictBehavior=rename would increment the folder value if it exists
how can I add the @microsoft.graph.conflictBehavior into my request?
Here's the code which creates the folder using drive Item
var foldertoCreate = new DriveItem {
Name = $"TestFolder",
Folder = new Folder (),
};
var newFolder = await _graphClient.Drive
.Items["MyParent_Item_Id"]
.Children
.Request ()
.AddAsync (foldertoCreate);
回答1:
I believe you should be able to add the annotation manually via AdditionalData
. Obviously this isn't ideal, but I cannot see another way to do it with the current SDK.
var foldertoCreate = new DriveItem
{
Name = $"TestFolder",
Folder = new Folder(),
AdditionalData = new Dictionary<string, object>
{
{ "@microsoft.graph.conflictBehavior", "rename" }
},
};
var newFolder = await _graphClient.Drive
.Items["MyParent_Item_Id"]
.Children
.Request()
.AddAsync(foldertoCreate);
来源:https://stackoverflow.com/questions/45910274/how-to-specify-microsoft-graph-conflictbehavior-in-the-request-body-in-onedrive