I struggled with this for too long, and the answer was right in front of me.
For me, the comment that Marek Kembrowski posted to the original question, was exactly what I needed to do, but I glazed over it because it was a comment, so I'm going to reiterate what Marek said in my own words so that hopefully the next person that comes along with this issue won't miss the comment posted above.
In sharepoint, when you create a column, there are two text fields where you give information to describe the field, Column Name and Description.
What KILLED me, was that the sharepoint site was set up with the Column name [OrderID] and a different description [CON].
Here you can see what Sharepoint looks like with the OrderID created first and the OrderID I created after I figured out the problem . . . The difference is one of the OrderID column names says OrderID ;)
The ONLY way I can see the original column name, is to Hover over the column in the Library Settings as Marek mentioned above . . . this will show the link at the bottom of the browser. If you click to edit it . . . it's not even right . . . doesn't even show anything about the real column name . . .even shows the description name in the column name field . . . GGRRRRRRR!!!!!
Anyhow, Here is the code I used to retrieve the data:
// Starting with ClientContext, the constructor requires a URL to the
// server running SharePoint.
ClientContext context = new ClientContext(siteUrl);
// The SharePoint web at the URL.
Web web = context.Web;
List docList = context.Web.Lists.GetByTitle("OrderDocuments");
CamlQuery query2 = new CamlQuery();
//This query will NOT work . . .CON is not a column in the sharepoint repository
//query2.ViewXml = "<View><Query><Where><Eq><FieldRef Name='CON' /><Value Type='Number'>4</Value></Eq></Where></Query></View>";
//This query WILL WORK. The actual Column name is OrderID in Sharepoint
query2.ViewXml = "<View><Query><Where><Eq><FieldRef Name='OrderID' /><Value Type='Number'>4</Value></Eq></Where></Query></View>";
ListItemCollection collListItem = docList.GetItems(query2);
context.Load(collListItem);
context.ExecuteQuery();
+1 to Marek for the correct solution above. I wish I'd seen it the first time I found this page.
Name
field. – TweedySPListItem[string fieldName]
) Display Names have to be used, in some (likeSPQuery
) Internal Names have to be used. Easiest way to check, what's the Internal Name of your field, is to go to field definition on SharePoint site and check Query string in url. For example:http://localhost/_layouts/FldEdit.aspx?List={F8645DD3-CE80-4ECF-849F-6F851EECA2A7}&Field=LocalNumber
myLocal Number
field has internal nameLocalNumber
. – Tweedy