Web.GetFileByServerRelativeUrl throws “Value does not fall within expected range”

。_饼干妹妹 提交于 2019-12-23 07:03:48

问题


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

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

When I execute this, I get a ServerException :

Value does not fall within the expected range.

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

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?

Thanks


回答1:


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


来源:https://stackoverflow.com/questions/21254703/web-getfilebyserverrelativeurl-throws-value-does-not-fall-within-expected-range

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