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 a 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();    
               
You can download all source file from: http://www.codeplex.com/camlquery
or:http://www.codeplex.com/camlquery/Release/ProjectReleases.aspx
 
相关: WSS3.0开发--你还在为写CAML痛苦吗?

posted on 2008-02-04 23:29  jianyi  阅读(3498)  评论(13编辑  收藏  举报