问题描述
我有一个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
:
由于我可以从库中添加/检索项目,并且上下文用户是 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引发“值未在预期范围内".的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!