Web.GetFileByServerRelativeUrl引发“值未在预期范围内". [英] Web.GetFileByServerRelativeUrl throws "Value does not fall within expected range"

查看:169
本文介绍了Web.GetFileByServerRelativeUrl引发“值未在预期范围内".的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个SP Online网站,用于存储文档,添加/检索文档没有问题,但是在删除流程中,检索File对象时出现错误.

I have a SP Online site where I store Documents, I have no issues adding/retrieving documents but in the delete flow I get an error during retrieval of a File object.

public static void DeleteDocument()
{
    using (ClientContext ctx = ClientContextFactory.Create("https://my-sponline-site.sharepoint.com/sites/documentsite"))
    {
        Web web = ctx.Web;
        ctx.Load(web);
        ctx.ExecuteQuery();

        string relativeUrl = "/Documents/images.jpg";

        File file = web.GetFileByServerRelativeUrl(relativeUrl);
        ctx.Load(file);
        file.DeleteObject();

        ctx.ExecuteQuery();
    }
}

文件的完整网址为" https://my -sponline-site.sharepoint.com/sites/documentsite/Documents/images.jpg "(2016年12月7日不再可用)

Full Url of the file is "https://my-sponline-site.sharepoint.com/sites/documentsite/Documents/images.jpg" (No more accessible 2016-12-07)

执行此操作时,我得到一个ServerException:

When I execute this, I get a ServerException :

值不在预期范围内.

Value does not fall within the expected range.

由于我可以从库中添加/检索项目,并且上下文用户是 administrator ,因此Context工作正常.

The Context is working fine as I'm able to add/retrieve items from the library and the context user is administrator.

我尝试将Web网址添加到relativeUrl中,因此它应该是"/documentsite/Documents/images.jpg",但出现相同的错误.

I tried adding the web url to the relativeUrl so it would be "/documentsite/Documents/images.jpg" but I get the same error.

我似乎无法解决这个问题,有什么建议吗?

I can't seem to figure this out, any suggestions?

谢谢

推荐答案

string relativeUrl = "/sites/documentsite/Documents/images.jpg";

这篇关于Web.GetFileByServerRelativeUrl引发“值未在预期范围内".的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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