CSOM File.MoveTo返回“不支持此操作”错误 [英] CSOM File.MoveTo Returns "This operation is not supported" Error

查看:79
本文介绍了CSOM File.MoveTo返回“不支持此操作”错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用SP 2013 CSOM中的File.MoveTo将文档从一个库移动到同一站点上的另一个库。这是我的代码:

I'm trying to move a document from one library to another library on the same site using File.MoveTo in SP 2013 CSOM. Here's my code:

using (ClientContext context = new ClientContext(sharePointUrl))
{
     Web web = context.Web;
     File file = item.File;
     context.Load(file);
     context.ExecuteQuery();
     file.MoveTo(destFileName, MoveOperations.Overwrite);
     context.ExecuteQuery();
}


看起来非常简单,但在context.ExecuteQuery()调用中,我收到错误消息"此操作不受支持。" 没有其他有用的信息。但是,当我尝试使用CopyTo而不是MoveTo时,它可以正常工作。 我宁愿使用MoveTo
,所以我不必删除代码中的源文件,但我必须这样做。 只是想知道是否有人知道为什么MoveTo可能会失败。谢谢。

Seems pretty straightforward, but on the context.ExecuteQuery() call, I'm getting the error message "This operation is not supported."  No other helpful info. However, when I try CopyTo instead of MoveTo, it works fine.  I'd rather use MoveTo so I don't have to delete the source file in my code, but I will I have to.  Just wondering if anyone has any insight as to why MoveTo might be failing. Thanks.

推荐答案

此类问题通常与目标网址格式(示例中为destFileName)有关。您必须使用服务器相对URL作为目标文件URL。见例子,例如这里:

CSOM移动文件一个文件夹另一个文件夹
such problems are often related with target url format (destFileName in your example). You have to use server relative url for destination file url. See example e.g. here: CSOM move the files one folder another folder.


这篇关于CSOM File.MoveTo返回“不支持此操作”错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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