sharepointcaml

CAML query is returning all the list items


I have the following CAML query

CamlQuery camlQuery = new CamlQuery();
camlQuery.ViewXml = "<Query><Where><Eq><FieldRef Name='RiskRequestID'/><Value Type='Text'>" + r.id + "</Value></Eq></Where></Query>";
ListItemCollection oListItems = context.Site.RootWeb.GetList(UFSsiteUrl + "Lists/RiskManagement/").GetItems(camlQuery);
context.Load(oListItems);
context.ExecuteQuery();

to get the item with the entered RiskRequestID.. currently instead of getting one item i am getting all the items inside the list.. any advice?

and the RiskRequestID is a SharePoint field of type Single Line of text.


Solution

  • Add tag inside camlQuery.viewXml:

    camlQuery.ViewXml = "<View><Query><Where><Eq><FieldRef Name='RiskRequestID'/><Value Type='Text'>" + r.id + "</Value></Eq></Where></Query></View>";