Reputation: 9900
I'm loading a SharePoint list using the client service object model (SharePoint 2013 on-premise). 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
Typically I believe this happens when the name being referenced in the following line doesn't match what's in SharePoint's backend:
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. I've also used SP Caml Query Helper 2013
and the field names appear to be correct.
How can I find the correct field names that I should be referencing?
Upvotes: 0
Views: 1173
Reputation: 515
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
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.)
This isn't a complete list but it has most http://www.werockyourweb.com/url-escape-characters/
Upvotes: 1