如何在onedriveAPI的请求正文中指定@ microsoft.graph.conflictBehavior [英] How to specify @microsoft.graph.conflictBehavior in the request body in onedriveAPI

查看:80
本文介绍了如何在onedriveAPI的请求正文中指定@ microsoft.graph.conflictBehavior的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在满足以下要求的C#项目中:

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

  1. 创建一个没有退出的文件夹
  2. 检查是否已经存在,如果存在,则增加文件名.

从Onedrive API文档在OneDrive中创建新文件夹,表示设置@ microsoft.graph.conflictBehavior = rename将增加文件夹值(如果存在)

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

如何将@ microsoft.graph.conflictBehavior添加到我的请求中?

how can I add the @microsoft.graph.conflictBehavior into my request?

以下是使用驱动器Item创建文件夹的代码

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);

推荐答案

我相信您应该可以通过AdditionalData手动添加注释.显然这并不理想,但是我看不到使用当前SDK的另一种方法.

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);

这篇关于如何在onedriveAPI的请求正文中指定@ microsoft.graph.conflictBehavior的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆