2

I am using the below query to filter using lookup value

List list = parentCtx.Web.Lists.GetByTitle("ListName");
CamlQuery camlQuery = new CamlQuery();
camlQuery.ViewXml = "<View><Query><Where><Eq><FieldRef Name = 'ProjectFolder'/><Value Type = 'Lookup'>" + filtervalue +"</Value></Eq></Where></Query></View>";
parentCtx.Load(collListItem);
parentCtx.ExecuteQuery();

After this when I debug, the count of collListItem is 0.

1 Answer 1

3

I think you are missing one important line of code here.

ListItemCollection collListItem = list.GetItems(camlQuery);

Just place this line of code before

parentCtx.Load(collListItem);

And you will get your desired result.

Your final code should look like this:

List list = parentCtx.Web.Lists.GetByTitle("ListName");
CamlQuery camlQuery = new CamlQuery();
camlQuery.ViewXml = "<View><Query><Where><Eq><FieldRef Name = 'ProjectFolder'/><Value Type = 'Lookup'>" + filtervalue +"</Value></Eq></Where></Query></View>";
ListItemCollection collListItem = list.GetItems(camlQuery);
parentCtx.Load(collListItem);
parentCtx.ExecuteQuery();

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.