问题
I am trying to read some attributes from a file in SharePoint 2010 library using client object model. Here is the sample
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
But I am recieving exception.
A first chance exception of type 'Microsoft.SharePoint.Client.ServerException' occurred in Microsoft.SharePoint.Client.Runtime.dll
Additional information: Value does not fall within the expected range.
What I am doing wrong?
回答1:
The error Value does not fall within the expected range.
occurs since Web.GetFileByServerRelativeUrl method accepts serverRelativeUrl
parameter in the following format:
/Site_Name/SubSite_Name/Library_Name/File_Name
Example:
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();
}
来源:https://stackoverflow.com/questions/27404570/unable-to-retrieve-file-information-from-sharepoint-library-using-client-object