本文通过SPQuery的RowLimit属性来实现对moss文档库文档的只取一定条目的分页效果。
 
String queryString=="" +
        "Com
";

//查询'Status'包含Com的项;
 
SPList docLib= web.GetList(" http://xxxx ");
SPQuery query= new SPQuery();
query.Query=querysString;

//下面开始做判断,主要运用viewstate来存储相关值;
 
//查看viewstate是否为空,如果为空,则说明是首次查询,并把queryString的值赋给viewstate;
 if ( ViewState["querystring"] == null)
             ViewState["querystring"] = queryString;
             //下面判断不为空的情况,即页面已经做过查询了
               else
                {
                   
                   //此处判断queryString是否已改变,即查询条件是否改变
 
                    //下面的情况是查询条件改变:
                     if ( ViewState["querystring"].ToString() != queryString)
                    {
                    
                        Session["pageinfo"] = null;  //这个session是用来存储item.ListItemCollictionPosition;
                        ViewState["querystring"] = queryString;
                    }
                    else
                    {
                        if ( Session["pageinfo"] != null && repeat == 1)//repeat是用来区分是上一页还是下一页,1为下一页
                        {
                            string strpage = ((Microsoft.SharePoint.SPListItemCollectionPosition)Session["pageinfo"]).PagingInfo;
                            if ( ViewState["pageindex"] == null)//用来储存上一页,当前页,下一页的item.ListItemCollictionPosition,通过这个只来判断是那一页;
                            {
                                ViewState["pageindex"] = strpage;
                            }
                            else
                            {
                                strpage = ViewState["pageindex"] + ";" + strpage;
                                ViewState["pageindex"] = strpage;
                            }
                        }
                    }
                }
query.RowLimit = ( uint)docPerPage;//每页的文档数
 
 if (repeat == 1)
            {
                if (Session["pageinfo"] != null)
                    query.ListItemCollectionPosition = (Microsoft.SharePoint.SPListItemCollectionPosition)Session["pageinfo"];
            }
            if (repeat == 2)
            {
               //处理 ViewState["pageindex"];
                if ( ViewState["pageindex"].ToString().Contains(";"))
                {
                    string[] strpage = ViewState["pageindex"].ToString().Split(';');
                    Session["pageinfo"] = new Microsoft.SharePoint.SPListItemCollectionPosition(strpage[strpage.Length - 2]);
                    query.ListItemCollectionPosition = (Microsoft.SharePoint.SPListItemCollectionPosition)Session["pageinfo"];
                    ViewState["pageindex"] = null;
                    for (int j = 0; j < strpage.Length - 1; j++)
                    {
                        if (j == 0)
                            ViewState["pageindex"] = strpage[j];
                        else
                            ViewState["pageindex"] = ViewState["pageindex"] + ";" + strpage[j];
                    }
                }
                else
                    ViewState["pageindex"] = null;
            }
 
 SPListItemCollection items = docLib.GetItems(query);
//你可以处理你的items了
 
//最后还要处理item.ListItemCollictionPosition;
 query.ListItemCollectionPosition = items.ListItemCollectionPosition;
            Session["pageinfo"] = items.ListItemCollectionPosition;
            if ( Session["pageinfo"] == null)
            {
                lbNextPage.Enabled = false;
                lbNextPage2.Enabled = false;
            }
            else
            {
                lbNextPage.Enabled = true;
                lbNextPage2.Enabled = true;
            }
            if (ViewState["pageindex"] == null)
            {
                lbPrePage.Enabled = false;
                lbPerPage2.Enabled = false;
            }
            else
            {
                lbPrePage.Enabled = true;
                lbPerPage2.Enabled = true;
            }