I need to build a CAML query at runtime based on user input. The CAML query could be as simple as
<Where>
<Eq>
<FieldRef Name="Status" />
<Value Type="Text">Awaiting Completion</Value>
</Eq>
</Where>
or might include multiple AND and OR like
<Where>
<Or>
<Or>
<Eq>
<FieldRef Name="Status" />
<Value Type="Text">Awaiting Completion</Value>
</Eq>
<Eq>
<FieldRef Name="Status" />
<Value Type="Text">Ongoing</Value>
</Eq>
</Or>
<Eq>
<FieldRef Name="status" />
<Value Type="Text">Postponed</Value>
</Eq>
</Or>
</Where>
The problem is that as soon as I add a third Status to check as in the query above it generates an SPException
"One or more field types are not installed properly. Go to the list settings page to delete these fields"
A quick code snippet to reproduce the problem:
using (SPSite spSite = new SPSite("http://sp2010"))
{
using (SPWeb spWeb = spSite.OpenWeb("/test"))
{
SPQuery spQuery = new SPQuery();
spQuery.Query = "<Where><Or><Or><Eq><FieldRef Name=\"Status\" /><Value Type=\"Text\">Awaiting Completion</Value></Eq><Eq><FieldRef Name=\"Status\" /><Value Type=\"Text\">Ongoing</Value></Eq></Or><Eq><FieldRef Name=\"status\" /><Value Type=\"Text\">Postponed</Value></Eq></Or></Where>";
SPListItemCollection spListItemCollection = spWeb.Lists["Actions"].GetItems(spQuery);
foreach(SPListItem spListItem in spListItemCollection)
{
Console.WriteLine(spListItem.Title);
}
}
}
Console.ReadKey();
Any ideas?