Project Description
A CamlQuery library and SmartQuery WebPart project.

Features
  • Caml Query, to write caml query xml
  • Smart Query , SmartQuery Web Part and ListQuery Web Part

About the source
源代码中有2个文件夹:
CodeArt.SharePoint.CamlQuery 老代码,适用于SP2007和SP2010, 将不再维护
CodeArt.SharePoint.CamlQuery2013 新代码,适用于SP2010和SP2013, 将继续维护,
新代码中有2个项目文件,分别对应SP2010和SP2013,SP2013的项目文件需要用VS2012打开

Instructions

2009-3-33 publish the source code.
and with the source code , the a webpart called smartQueryWebpart, use this webpart , you can add query function to any list . Just as fllow :

SmartQueryOn2010.jpg

ListQueryWP2.jpg
ListQueryWP1.jpg

this is a blog entry for this webpart writed in chinese :
http://www.cnblogs.com/jianyi0115/archive/2008/02/15/1070158.html
http://www.cnblogs.com/jianyi0115/archive/2011/12/09/2282287.html

It's not a happy job to write caml query xml to return data from shrepoint list. So , I write the tool to make it easy.

the code example:

---------------------
using Microsoft.SharePoint;
using CodeArt.SharePoint.CamlQuery;

SPSite site = new SPSite("http://jyserver:81");

SPList list = site.RootWeb.Lists"Notice";

QueryField field1 = new QueryField("标题",false); //the second parameter explain if the first parameter is a internal name.
//or : QueryField field1 = new QueryField("Title"); //"Title" is internal name.
//DateTime type field
TypedQueryField<DateTime> field2 = new TypedQueryField<DateTime>("Expires");

//ModerationStatus
TypedQueryField<SPModerationStatusType> modField = new TypedQueryField<SPModerationStatusType>("_ModerationStatus", true);

//for lookup field
LookupQueryField field3 = new LookupQueryField ("Field1");

CamlExpression expr = field1.Contains("Test1");

SPListItemCollection items =
ListQuery
.From(list)
.Where(expr)
.OrderBy(expr && modField==SPModerationStatusType.Approved)
.GetItems();

//set the fields to be returned
items =
ListQuery.Select( field1,field2 )
.From(list)
.Where( field1..Contains("Test1") && field2 >= DateTime.Now.AddDays(-1) )
.OrderBy(field1)
.GetItems();

items =
ListQuery.Select( 10 , field1, field2 ) // limit result count.
.From(list)
.Where( field1..Contains("Test1") && field2 >= DateTime.Now.AddDays(-1) )
.OrderBy(field1)
.GetItems();

items =
ListQuery.Select( field1 , field2 )
.From(list)
.Where( field1..Contains("Test1") && field2 >= DateTime.Now.AddDays(-1) )
.OrderBy(field1,false)
.OrderBy(field2,true) //
.GetItems();

//query items in subfolders
items =
ListQuery.
.From(list,QueryScope.RecursiveAll)
.Where( field1..Contains("Test1") && field2 >= DateTime.Now.AddDays(-1) )
.GetItems();

----------------------

http://www.codeplex.com/camlquery

blog: http://jianyi0115.cnblogs.com

Download Source Code


Environment
  • .NET Framework 2.0
  • SharePoint2007/2010

Last edited Apr 25, 2013 at 8:54 AM by jianyi, version 25