Reputation: 81
I am trying to construct a CAML query for list item on SP2019 site. I have the below code returning the entire list. I read that if there is a issue in the query , all the items in the list are returned. Please advise.
List dashboardList = context.Web.Lists.GetByTitle("Dashboard");
CamlQuery camlQuery = new CamlQuery();
string searchfor = "CPPMC";
camlQuery.ViewXml = "<Query><Where><Eq><FieldRef Name = 'Title'/><Value Type ='Text'>" + searchfor+ "</Value></Eq></Where></Query>";
ListItemCollection listItems = dashboardList.GetItems(camlQuery);
context.Load(listItems);
context.ExecuteQuery();
foreach (ListItem item in listItems)
{
Console.WriteLine("{0},{1},{2}",item.Id,item["Title"], item["Processing_x0020_Date"]);
}
Upvotes: 0
Views: 1022
Reputation: 245
Have you tried -
camlQuery.ViewXml = "<View Scope='RecursiveAll'><Query><Where><Eq><FieldRef Name = 'Title'/><Value Type ='Text'>" + searchfor+ "</Value></Eq></Where></Query></View>";
Note - use scope = RecursiveAll if you have folders in the list/library
Upvotes: 2