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 :

smartquery1.gif

this is a blog entry for this webpart writed in chinese :
http://www.cnblogs.com/jianyi0115/archive/2008/02/15/1070158.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.

TypedQueryField<DateTime> field2 = new TypedQueryField<DateTime>("Expires");

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

SPListItemCollection items =
ListQuery.Select( field1)
.From(list)
.Where(expr)
.OrderBy(field1)
.GetItems();

items =
ListQuery.Select( field1)
.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();

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

@author: jianyi0115@163.com

http://www.codeplex.com/camlquery

blog: http://jianyi0115.cnblogs.com/
Last edited Jun 10 at 6:42 AM by jianyi, version 7

 

Want to leave feedback?
Please use Discussions or Reviews instead.

Archived page comments (3)

Updating...
© 2006-2009 Microsoft | About CodePlex | Privacy Statement | Terms of Use | Code of Conduct | Advertise With Us | Version 2009.10.27.15987