gpt4 book ai didi

c# - 无法使用客户端对象模型从 SharePoint 库中检索文件信息

转载 作者:太空宇宙 更新时间:2023-11-03 10:36:56 24 4
gpt4 key购买 nike

我正在尝试使用客户端对象模型从 SharePoint 2010 库中的文件中读取一些属性。这是示例

using SP = Microsoft.SharePoint.Client;

SP.ClientContext clientContext = new SP.ClientContext( "http://path/to/the/site" );
clientContext.Load( clientContext.Web );
clientContext.ExecuteQuery();

SP.File spFile = clientContext.Web.GetFileByServerRelativeUrl("/TestLibrary/sample.pdf");
clientContext.Load(spFile);
clientContext.ExecuteQuery(); //here we'll catch exception

但我收到异常。

A first chance exception of type 'Microsoft.SharePoint.Client.ServerException' occurred in Microsoft.SharePoint.Client.Runtime.dll

附加信息:值不在预期范围内。

我做错了什么?

最佳答案

错误 Value does not fall in the expected range. 发生自 Web.GetFileByServerRelativeUrl method接受以下格式的 serverRelativeUrl 参数:

/Site_Name/SubSite_Name/Library_Name/File_Name

例子:

using (var ctx = new ClientContext("https://intranet.contoso.com/news"))
{
var file = ctx.Web.GetFileByServerRelativeUrl("/news/Documents/SharePoint User Guide.docx");
ctx.Load(file);
ctx.ExecuteQuery();
}

关于c# - 无法使用客户端对象模型从 SharePoint 库中检索文件信息,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27404570/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com