使用SPSiteDataQuery中的一些问题。

SPSiteDataQuery可以进行在同一个网站集(Site Collection)中跨站点和跨列表的查询,使用这个类,可以比较方便的进行某一类文档的统计。特别是在使用Content Query Web Part无法做到的情况。

我在使用的过程中,也出现了一些有意思的问题,这里做一个记录,总结。

1. 利用内容类型(Content Type)查询的时候,如何包含这个内容类型(Content Type)以及其子类型。

<Where>
   <BeginsWith>
     <FieldRef Name="ContentTypeId"/>
     <Value Type="Text">0x0101</Value>
   </BeginsWith>
</Where>

这里一个技巧就是利用了Content Type IDs生成的一个规则。

默认的ContentTypeID,可以参考:Base Content Type Hierarchy

2. 查询文档库(Document Library)的时候没有返回结果。

默认情况下,SPSiteDataQuery仅仅只查询所有List的内容,这是因为默认的Lists属性的原因。默认List的值设置为:<Lists BaseType="0"/>,这个说明是搜索所有的List。

如果需要设置到搜索SPSiteDataQuery,需要设置<Lists BaseType="1"/>。

以下是一些默认值列表,更多说明参考SPSiteDataQuery.Lists Property

Value

Description

0

Generic list

1

Document library

3

Discussion forum

4

Vote or Survey

5

Issues list

3. 查询不到子网站的内容。

默认情况下,SPSiteDataQuery仅仅只查询当前网站的内容,这是因为默认的Webs属性的原因。如果搜索这个网站集,可以设置为<Webs Scope="SiteCollection" />

更多说明参考SPSiteDataQuery.Webs Property

posted @ 2011-06-23 10:51  Lambert Qin  Views(623)  Comments(1Edit  收藏  举报