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