跨网站跨列表查询SPSiteDataQuery

SharePoint2010官方参考SPSiteDataQuery

moss_tan_jun的空间SPSiteDataQuery使用说明

wss3.0官方参考SPSiteDataQuery

 

名称 说明
公共属性 Lists Gets or sets the inner XML that specifies which lists to include in the query.
公共属性 Query Gets or sets the inner XML that defines the query.
公共属性 RowLimit Gets or sets a limit for the number of items in the query that are returned per page.
公共属性 ViewFields Gets or sets the inner XML that describes the view fields used in the query.
公共属性 Webs Gets or sets the inner XML that specifies which Web sites to include in the query. as specified by the Scope attribute on the Webs tag in the query. By default, the query considers the current Web site, that is, the Web site from which the

属性说明补充

 1.Lists

 要查询的列表,可以通过<Lists />的属性去指定

  ServerTemplate ,BaseType 来限定列表范围,也可以直接用其子元素 <List ID="xxx">来指定特定的列表

  至于Hidden和MaxListLimit ,msdn说的很明白 

  特别要说的是<Lists/>子元素 

  <WithIndex FieldId="FieldID" Type="Text" Value="xx" />  Type必须是Text,

 查询 存在 FieldId 为"FieldID" 的Field,且此Field被索引的,且有条目此Field的值为"xx"的列表们

此为我测试过,至于是不是只能查询type为text的Field,????

例如,查询所有存在Fieldid =SPBuiltInFieldId.Title ,并且索引过,并且有SPLitsItem此Field的值为 InfoTest1的条目

 为什么会提供这样的查询了,莫非速度。。。。。

代码
            SPSiteDataQuery sdQuery  =   new  SPSiteDataQuery();
            SPList info2 
=  site.RootWeb.Lists[ " info2 " ];
            SPList infoList 
=  site.RootWeb.Lists[ " InfoList " ];
            sdQuery.Lists 
=
              
" <Lists> "
            
// + "  <List ID=\"" + info2.ID.ToString() + "\" />"
            
// + "  <List ID=\"" + infoList.ID.ToString() + "\" />"
             +   "   <WithIndex FieldId=\ ""  + SPBuiltInFieldId.Title +  " \ "  Type=\ " Text\ "  Value=\ " InfoTest1\ "  /> "
            
+   " </Lists> " ;
            sdQuery.Query 
=
              
" <Where> "
            
+   "   <Contains> "
            
+   "     <FieldRef Name=\ " Title\ "  /> "
            
+   "     <Value Type=\ " Text\ " > "   +   " info "   +   " </Value> "
            
+   "   </Contains> "
            
+   " </Where> " ;
            sdQuery.ViewFields 
=   " <FieldRef Name=\ " Title\ " /> " ;
            DataTable dt 
=  site.RootWeb.GetSiteData(sdQuery);

 

 

2.Query

  和SPQuery的语法很一致

3.RowLimit

  条数限制

4.ViewFields

 除此之外还会额外的为你返回三个栏

    WebId:列表所在的SPWeb的ID

    ListId:SPListItem所在SPList的ID

    ID:SPListItem的ID

  要返回的Fields,大小写敏感。

  如果被查询的列表不存在ViewFields的某个Field,那么这个列表不会被查出任何数据 。
  如果你的列表有Field 类似 webid,listid,不管大小写,那么系统返回的WebId和ListId将为你列表栏实际的值,所以给Field取名字时,三思而

  后行。

   

5.Webs

  三个值

 <Webs Scope="SiteCollection" /> ,包含当前网站所在的网站集 (SPSite)下所有网站 (SPWeb)以及子网站 (SPWeb)

 <Webs Scope="Recursive" /> ,包含当前网站以及其下的所有子网站

  缺省 ,仅仅包含当前SPWeb

  

你可能感兴趣的:(query)