简体   繁体   English

如何使用 Graph Api 替换 Onedrive 中的文件?

[英]How can i replace a file in Onedrive USING THE Graph Api?

I have a fie that already exists in a Onedrive directory , filename is TestFile.txt我有一个已经存在于 Onedrive 目录中的文件,文件名为 TestFile.txt

If i try to move a file with the same name to that directory it gives the error如果我尝试将具有相同名称的文件移动到该目录,则会出现错误

    {"error":{"code":"nameAlreadyExists","message":"Name already exists",

I am copying the file to the destination folder as follows我将文件复制到目标文件夹如下

I setup a Patch request to th endpoint /me/drive/items/{Id}我向端点 /me/drive/items/{Id} 设置了一个补丁请求

set the body and send the request.设置正文并发送请求。

        var filebody = new { parentReference = new { id = folderDestId }, name = fileName };
        request.AddJsonBody(filebody);
        var response = client.Execute(request);

But the file is not moved to the new locaion and it doesnt replace the existing file there.但是该文件不会移动到新位置,也不会替换那里的现有文件。

Do i need to delete the file first and then move , or is there something the body I can send to make it automatically replace the file ?我需要先删除文件然后再移动,还是我可以发送正文以使其自动替换文件?

When uploading your file, there is an instance attribute called " conflictBehavior " that you can set to "replace" to achieve that.上传文件时,有一个名为“ conflictBehavior ”的实例属性,您可以将其设置为“替换”以实现该目的。 Note that this is an instance attribute and should be included in the URL instead of the request body.请注意,这是一个实例属性,应包含在 URL 中而不是请求正文中。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何使用OneDrive API将文件上传到OneDrive上的共享文件夹中? - How can I upload files into a shared folder on OneDrive using OneDrive API? 使用 Graph API 将文件 (> 4MB) 上传到 OneDrive - Upload file (> 4MB) to OneDrive using Graph API 如何使用OneDrive SDK更新存储在OneDrive(业务)上的文件的创建和/或最后修改时间 - How can I update the creation and/or the last modified time of a file stored on OneDrive (Business) using the OneDrive SDK 如何使用图形 API 从 OneDrive 获取文件共享人员详细信息 - How to get the file shared persons details from OneDrive using graph API 如何使用 Onedrive Graph API 删除用户对项目的权限? - How to remove permissions of a user on an item using Onedrive Graph API? 如何在 c# 中使用 Microsoft Graph Api 上传到 OneDrive - How to upload to OneDrive using Microsoft Graph Api in c# 使用Graph API使用C#上传到Onedrive - Upload to Onedrive with C# using Graph API 使用Microsoft图表将文件上传到onedrive以进行业务 - Uploading file to onedrive for business using Microsoft graph 使用 Microsoft Graph API 将文件上传到 MVC 应用程序中的 onedrive,权限错误 - Using Microsoft Graph API to upload file to onedrive in MVC Application, Error with permissions 图形API-我无法在OneDrive中获取有关共享项目的邀请信息 - Graph api- i can't get the invitation information about an shared item in the onedrive
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM