CAML (Collaborative Application Markup Language) is the XML-based language that will help you to perform a data manipulation task in SharePoint. It is easy to relate a list to CAML if you compare it to a database table and query.
CAML Query Comparison Operators:
2 conditions
1. http://sharepoint-works.blogspot.com/2012/05/caml-query-tutorial-for-sharepoint.html#.UclenpyGa3V
2. http://buli.waw.pl/caml-query-multiple-conditions-in-and-or-clause/
CAML Query Comparison Operators:
- Contains - Contains a given text value
- Eq - Equal to
- Geq - Greater than or equal to
- Gt - Greater than
- Leq - Less than or equal to
- Lt - Less than
- Neq - Not equal to
- DateRangesOverlap - Compares dates in recurring events to determine if they overlap
- IsNotNull - Is not null
- IsNull - Is null
2 conditions
3 conditionscamlQuery.ViewXml = @"<View><Query><Where><And><And><Eq><FieldRef Name='AssignedTo'/> <Value Type='User'>" + AssignTo + @"</Value></Eq></And><Leq><FieldRef Name='Priority' /> <Value Type='Text'>" + Priority + @"</Value></Leq></And></Where></Query></View>";
4 conditionscamlQuery.ViewXml = @"<View><Query><Where><And><And><Eq><FieldRef Name='AssignedTo'/> <Value Type='User'>" + AssignTo + @"</Value></Eq><Leq><FieldRef Name='Created'/><Value Type='DateTime' IncludeTimeValue='TRUE' >" + Created.ToString("yyyy-MM-ddTHH:mm:ssZ") + @"</Value></Leq></And><Geq><FieldRef Name='Created'/><Value Type='DateTime' IncludeTimeValue='TRUE' >" + Created.ToString("yyyy-MM-ddTHH:mm:ssZ") + @"</Value></Geq></And></Where></Query></View>";
Crete multi condition QuerycamlQuery.ViewXml = @"<View><Query><Where><And><And><Eq><FieldRef Name='Reference'/> <Value Type='Text'>" + Reference + @"</Value></Eq><Eq><FieldRef Name='AssignedTo'/> <Value Type='User'>" + AssignTo + @"</Value></Eq></And><And><Eq><FieldRef Name='Priority' /> <Value Type='Text'>" + Priority + @"</Value></Eq><Eq><FieldRef Name='Reference'/> <Value Type='Text'>" + Reference + @"</Value></Eq></And></And></Where></Query></View>";
References:private static string CreateCAMLConditions(List<string> conditions, string type){// No conditions => empty responseif (conditions.Count == 0) return "";// Initialize temporary variablesstring typeStart = (type == "And" ? "<And>" : "<Or>");string typeEnd = (type == "And" ? "</And>" : "</Or>");// Build hierarchical structurewhile (conditions.Count >= 2){List<string> complexConditions = new List<string>();for (int i = 0; i < conditions.Count; i += 2){if (conditions.Count == i + 1) // Only one condition leftcomplexConditions.Add(conditions[i]);else // Two condotions - mergecomplexConditions.Add(typeStart + conditions[i] + conditions[i + 1] + typeEnd);}conditions = complexConditions;}return conditions[0];}
1. http://sharepoint-works.blogspot.com/2012/05/caml-query-tutorial-for-sharepoint.html#.UclenpyGa3V
2. http://buli.waw.pl/caml-query-multiple-conditions-in-and-or-clause/
No comments:
Post a Comment