How to specify @microsoft.graph.conflictBehavior in the request body in onedriveAPI

不问归期 提交于 2019-12-24 00:22:14

问题


I'm working on a C# project with these requirements:

  1. Create a Folder if it doesn't exits
  2. 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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!