I'm very new to CamlQuery and need a bit of help getting this to work.
I installed a tool called CamlDesigner to help me generate the XML needed to filter a collection in Sharepoint, but the XML query that CamlDesigner constructs does not work in my C# codebehind. I have an ID field that I am trying to filter by and I simply want to retrieve an item from Sharepoint where ID = 1 (or 2 or 3 or whatever).
Here is the Caml query generated by the designer:
<Where>
<Eq>
<FieldRef Name='ID' />
<Value Type='Counter'>1</Value>
</Eq>
</Where>
Here is my C# code where I am attempting to incorporate this Caml query. The C# works, but it is returning every item from "My SP Coll" as opposed to only returning the item where ID equals 1.
// Sharepoint web service to retrieve categories items there
ClientContext clientContext = new ClientContext("https://myweb.dev.com/SP");
List oList = clientContext.Web.Lists.GetByTitle("My SP Coll");
CamlQuery camlQuery = new CamlQuery();
camlQuery.ViewXml = "<Query><Where><Eq><FieldRef Name='ID'/><Value type='Counter'>" + ID.ToString() + "</Value></Eq></Where></Query>";
Microsoft.SharePoint.Client.ListItemCollection collListItem = oList.GetItems(camlQuery);
clientContext.Load(collListItem);
clientContext.ExecuteQuery();
foreach (Microsoft.SharePoint.Client.ListItem oListItem in collListItem) {
string ID = oListItem["ID"].ToString();
}
Thanks for the help!