I am trying to filter a SPListItemCollection with CAML but I don't get the results I want.

Here is my code:

query.Query = "<Eq><FieldRef Name=\"Title\" /><Value Type=\"Text\">" + project.Split('/')[1].ToString().Trim() + "</Value></Eq>";

This should return one item as Title field is unique. However, when I use SP Caml Query Helper, I get all items returned. When I execute the code in Sharepoint, I get an error that a field is not correctly installed.

Anybody see a problem with my code?

  • You are missing the <Where> clause around your <Eq> tags – Robert Lindgren Sep 4 '15 at 15:50
  • I already tried that but got the same behavior. grrrr sometimes I hate sharepoint :( – LeonidasFett Sep 4 '15 at 15:52
  • ok I managed to get it working so far so I don't get the error anymore even when executing code through sharepoint. but I still get all items returned even though the column I am querying is unique... – LeonidasFett Sep 4 '15 at 15:55
  • also tried with <View> tag, same problem persists... – LeonidasFett Sep 4 '15 at 16:11
  • Use U2U caml builder. You have options to see the CSOM/SSOM code for that query. It always works. – Akhoy Sep 4 '15 at 17:00

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.