Spsitedataquery can be used for cross-site and cross-list queries in the same site collection. Using this class, you can conveniently collect statistics on a certain type of documents. Especially when Content Query Web parts cannot be used.
I also encountered some interesting problems during the use process. Here is a record and summary.
1. How to include the content type and its subtypes when querying by content type.
<Where>
<Beginswith>
<Fieldref name = "contenttypeid"/>
<Value type = "text"> 0x0101 </value>
</Beginswith>
</Where>
One trick here is to use a rule generated by content type IDs.
The default contenttypeid. For details, refer to base content type hierarchy.
2. No results are returned when you query the document library.
By default, spsitedataquery only queries the content of all lists. This is because of the default lists attribute. The default value of list is <lists basetype = "0"/>, which indicates searching all lists.
To search for spsitedataquery, set <lists basetype = "1"/>.
The following lists some default values. For more information, see spsitedataquery. Lists property.
Value |
Description |
0 |
generic list |
1 |
document library |
3 |
Discussion Forum |
4 |
vote or survey |
5 |
Issues List |
3. The contents of the subwebsite cannot be found.
By default, spsitedataquery only queries the content of the current website. This is because of the default webs attribute. If you search for this website set, you can set it to <webs scope = "sitecollection"/>
For more information, see spsitedataquery. webs property.