SharePoint CAML QueryBuilder Helper class

It may be far from perfect but I find it pretty useful. Especially with complicate/dynamic conditions.
It gives some intellisence and helps with native CAML binary condition limitations.

Happy coding,
Vladimir

Simple sample:

query.Query =
QueryBuilder.Where(
QueryBuilder.LEQ(QueryBuilder.FieldDateValue("PublishDateTime",DateTime.Now))
)+
QueryBuilder.OrderBy(QueryBuilder.FieldRef("PublishDateTime", QueryBuilder.FieldRefAttr.Descending));

More complicate (note how it handles more then two AND conditions):

query.Query = QueryBuilder.Where(
QueryBuilder.AND(
QueryBuilder.EQ(QueryBuilder.FieldStringValue("RefNumber", number)),
QueryBuilder.EQ(QueryBuilder.FieldStringValue("ContentType", OrderContentType)),
QueryBuilder.BEGINSWITH(QueryBuilder.FieldStringValue("Title", "ABC"))
)
);

Dynamic:


Dictionary<string, string> conditions = new Dictionary<string, string>();

...........

string queryCondtions = null;
foreach (string field in conditions.Keys)
{
queryCondtions = QueryBuilder.AND(
queryCondtions,
QueryBuilder.EQ(QueryBuilder.FieldStringValue(field, conditions[field]))
);
}

query.Query = QueryBuilder.Where(queryCondtions);
query.ViewAttributes = QueryBuilder.SearchScope(QueryBuilder.ViewAttribute.SeachInAllFordersForItemsAndFolders);


Last edited May 2, 2013 at 4:01 PM by bva1971m, version 5