[英]How can I discover the right internal names to use with a SPList using CSOM
我正在使用客户端服务对象模型(SharePoint 2013内部部署)加载SharePoint列表。 我正在使用以下代码:
private void buttonRefreshOrders_Click(object sender, RoutedEventArgs e)
{
using (var ctx = new ClientContext("http://sharepoint/ci/resources"))
{
var list = ctx.Web.Lists.GetByTitle("Resource Order Form Content");
var query = new CamlQuery
{
ViewXml =
@"<Where><Or><Eq><FieldRef Name=""Status""></FieldRef><Value Type=""Text"">Approved</Value></Eq><IsNotNull><FieldRef Name=""Status"" /></FieldRef></IsNotNull></Or></Where>"
};
var collListItem = list.GetItems(query);
ctx.Load(collListItem);
ctx.ExecuteQuery();
if (collListItem.Count == 0)
{
MessageBox.Show(
"No orders are currently within the queue.",
"Information Center",
MessageBoxButton.OK,
MessageBoxImage.Information);
}
else
{
MessageBox.Show("Success!");
foreach (var item in collListItem)
{
MessageBox.Show(item["Status"].ToString());
}
}
}
}
我收到异常:
Microsoft.SharePoint.Client.dll中发生了类型为“ Microsoft.SharePoint.Client.PropertyOrFieldNotInitializedException”的未处理异常
通常,我相信当以下行中引用的名称与SharePoint后端中的名称不匹配时,会发生这种情况:
MessageBox.Show(item["Status"].ToString());
但是我不明白这里的情况,因为我在CamlQuery中使用了完全相同的命名。 我还使用了SP Caml Query Helper 2013
,字段名称似乎正确。
如何找到应该参考的正确字段名?
转到共享点站点上的列表,转到列表设置,然后单击要查找的列以获取正确的名称,然后它将在地址栏中。
EG:YourSite / _layouts / FldEdit.aspx?List = {Guid}&Field = Cost%5Fx0020%5FCentre%5Fx0020%5FCode
在这种情况下,您想要的字段名称为Cost_x0020_Centre_x0020_Code(%5F是“ _”,%20是空格,等等,您可能需要找出这些列表)。
这不是完整的列表,但其中包含大多数http://www.werockyourweb.com/url-escape-characters/
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.