[英]How can I discover the right internal names to use with a SPList using CSOM
I'm loading a SharePoint list using the client service object model (SharePoint 2013 on-premise). 我正在使用客户端服务对象模型(SharePoint 2013内部部署)加载SharePoint列表。 I'm using the following code:
我正在使用以下代码:
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());
}
}
}
}
I receive the exception: 我收到异常:
An unhandled exception of type 'Microsoft.SharePoint.Client.PropertyOrFieldNotInitializedException' occurred in Microsoft.SharePoint.Client.dll
Microsoft.SharePoint.Client.dll中发生了类型为“ Microsoft.SharePoint.Client.PropertyOrFieldNotInitializedException”的未处理异常
Typically I believe this happens when the name being referenced in the following line doesn't match what's in SharePoint's backend: 通常,我相信当以下行中引用的名称与SharePoint后端中的名称不匹配时,会发生这种情况:
MessageBox.Show(item["Status"].ToString());
However I don't understand how that's the case here as I've used this exact same naming within my CamlQuery. 但是我不明白这里的情况,因为我在CamlQuery中使用了完全相同的命名。 I've also used
SP Caml Query Helper 2013
and the field names appear to be correct. 我还使用了
SP Caml Query Helper 2013
,字段名称似乎正确。
How can I find the correct field names that I should be referencing? 如何找到应该参考的正确字段名?
Goto the list on your sharepoint site, goto list settings, then click on the column your looking to get the correct name of, it will then be in the address bar. 转到共享点站点上的列表,转到列表设置,然后单击要查找的列以获取正确的名称,然后它将在地址栏中。
EG: YourSite/_layouts/FldEdit.aspx?List={Guid}&Field=Cost%5Fx0020%5FCentre%5Fx0020%5FCode EG:YourSite / _layouts / FldEdit.aspx?List = {Guid}&Field = Cost%5Fx0020%5FCentre%5Fx0020%5FCode
in this case the name of the field you want is Cost_x0020_Centre_x0020_Code (%5F is an "_" %20 is a space, etc you may need to find out a list of these.) 在这种情况下,您想要的字段名称为Cost_x0020_Centre_x0020_Code(%5F是“ _”,%20是空格,等等,您可能需要找出这些列表)。
This isn't a complete list but it has most http://www.werockyourweb.com/url-escape-characters/ 这不是完整的列表,但其中包含大多数http://www.werockyourweb.com/url-escape-characters/
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.