我需要在插件中更改一个SharePoint文件夹的名称,该文件夹的名称是联系人的全名,但如果名称有错误,则需要有一个插件来在SharePoint中更改文件夹名称。我找到了一种方法来实现这个目标,但是为了完成此操作,我需要使用CamlQuery获取文件夹。(这是SharePoint 2010)
以下是我获取文件夹的步骤:
ClientContext clientContext = new ClientContext(siteUrl);
clientContext.Credentials = new NetworkCredential(login, password);
Web web = clientContext.Web;
List list = web.Lists.GetByTitle(listName);
string FolderFullPath = siteUrl + "contact/" + folderName;
CamlQuery query = new CamlQuery();
query.ViewXml = "<View Scope=\"RecursiveAll\"> " +
"<Query>" +
"<Where>" +
"<And>" +
"<Eq>" +
"<FieldRef Name=\"FSObjType\" />" +
"<Value Type=\"Integer\">1</Value>" +
"</Eq>" +
"<Eq>" +
"<FieldRef Name=\"Title\"/>" +
"<Value Type=\"Text\">" + folderName + "</Value>" +
"</Eq>" +
"</And>" +
"</Where>" +
"</Query>" +
"</View>";
if (relativePath.Equals(string.Empty))
{
query.FolderServerRelativeUrl = "/lists/" + listName;
}
else
{
query.FolderServerRelativeUrl = "/lists/" + listName + "/" + relativePath;
}
var folders = list.GetItems(query);
clientContext.Load(list);
clientContext.Load(list.Fields);
clientContext.Load(folders, fs => fs.Include(fi => fi["Title"],
fi => fi["DisplayName"],
fi => fi["FileLeafRef"]));
clientContext.ExecuteQuery();
但我一直收到错误信息:“值不在预期范围内”。
以下是日志:
Unhandled Exception: System.ServiceModel.FaultException`1[[Microsoft.Xrm.Sdk.OrganizationServiceFault, Microsoft.Xrm.Sdk, Version=5.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35]]: Value does not fall within the expected range.Detail:
<OrganizationServiceFault xmlns:i="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://schemas.microsoft.com/xrm/2011/Contracts">
<ErrorCode>-2147220891</ErrorCode>
<ErrorDetails xmlns:d2p1="http://schemas.datacontract.org/2004/07/System.Collections.Generic">
<KeyValuePairOfstringanyType>
<d2p1:key>OperationStatus</d2p1:key>
<d2p1:value xmlns:d4p1="http://www.w3.org/2001/XMLSchema" i:type="d4p1:string">0</d2p1:value>
</KeyValuePairOfstringanyType>
</ErrorDetails>
<Message>Value does not fall within the expected range.</Message>
<Timestamp>2015-05-26T07:16:43.90779Z</Timestamp>
<InnerFault i:nil="true" />
</OrganizationServiceFault>