Use SPSiteDataQuery in sharepoint for cross-list Query

Source: Internet
Author: User

What about the SPSiteDataQuery object? Powerful functions. There is also a SPQuery object in sharepoint. One is queried based on the list and the other can be queried across lists!

For example! Now we want to query the tasks in the task list under the site in the state of "unfinished! In this way, I can know which boys are not working very hard... (haha ),

What if I use a SPQuery object? You must know the task List. What about the sub-site points under the site? What about the subsite task List? You need to search for each one! In this way, we can directly use the SPSiteDataQuery object to query all the task IDs in the "not completed" status on the site. Remember, it can be cross-list!

What happens when I use SPSiteDataQuery? Every time I want to learn SPSiteDataQuery objects, I want to go to google (or baidu) every time. Now I am in trouble, so I will record it! The Reference Links are listed below. Of course, the parameter descriptions of SPSiteDataQuery users are collected in the links!

Private void SiteDataQueryTest () {using (SPWeb web = new SPSite ("http: // dg-mlwang /"). openWeb () {SPSiteDataQuery query = new SPSiteDataQuery (); query. lists = "<Lists ServerTemplate = \" 107 \ "/>"; // query. lists = "<Lists BaseType = \" 0 \ "/>"; // query. lists = "<Lists Hidden = \" true \ "/>"; // The default value is the current web, excluding the subsite query. webs = "<Webs Scope = 'sitecollect'/>"; query. query = "<Where> <Eq> <FieldRef Name = \" Status \ "/>" + "<Value Type = \" Text \ "> unfinished </Value> </ eq> </Where> "; // query. viewFields = "<FieldRef Name = \" Title \ "/>"; DataTable items = web. getSiteData (query); if (items. rows. count> 0) {for (int I = 0; I <items. rows. count; I ++) {string listID = items. rows [I] [0] + ""; SPList list = web. lists [new Guid (listID)]; Response. write ("Title:" + list. title + "<br/>") ;}} GridView1.DataSource = items; GridView1.DataBind (); // modify the number of days when a New identifier is displayed when a New document is uploaded. // web. site. webApplication. daysToShowNewIndicator = 1 ;}}

Query. webs:

This element has only one attribute: Scope. There are three values that can be assigned to it, although there are only two in MSDN .....

①"<Webs Scope = 'sitecollect'/>"Including all websites and sub-Websites under the website where the current website is located)

②"<Webs Scope = 'cursive '/>", Including the current website (Web) and all its sub-websites (Web)

③Default, Only contains the current website (Web)

 

Query. lists:

This element defines your search range in the Document library or Lists.
Four attributes are available: BaseType, ServerTemplate, Hidden, and MaxListLimit.
In addition, there are two sub-elements: List and WithIndex. You can use sub-elements to limit the search conditions to a relatively small range.
The following describes attributes.

①BaseType(For example, "<Lists BaseType = '1'/> ")

Note that the default value of this attribute is "<Lists BaseType = '0'/>", that is, all Lists outside the document library will be queried by default or when an error occurs in this attribute setting.

②ServerTemplate(For example, "<Lists ServerTemplate = '20170901'/> ")
Search for a list of the specified type (850 is the page library list type ). When an error occurs in the value of this attribute, It is queried by default.

③Hidden(For example, "<Lists ServerTemplate = '000000' den = 'true'/> ")
Allows you to search for hidden lists. By default, all non-hidden lists are searched.

④MaxListLimit (For example, "<Lists BaseType = '1' MaxListsLimit = '000000'/> ")
Defines the total number of search lists. If this number is exceeded, SPSiteDataQuery throws an exception of SPException. The default value of this attribute is 1000. When this attribute is set to 0, the number of lists to be searched is not limited.

Query. ViewFields:

This element defines the Fields returned (list columns), that is, the columns that the DataTable will contain as the search result ). For example:
<ViewFields>

<FieldRef Name = "Title" Nullable = "TRUE"/>

</ViewFields>

①Name(Example: <FieldRef Name = "Title"/>)

②Nullable(For example, <FieldRef Name = "Title" Nullable = "TRUE"/> ).

The Nullable attribute is optional. We know that not all lists in MOSS contain the same columns. For example, when querying a list, SPSiteDataQuery finds that a specified column in ViewFields does not exist in the list, the list is ignored. This can be avoided when "Nullable" is specified as "TRUE". No matter whether this column exists or not, this type of table will be queried, but the column will be blank in the returned DataTable.

Query. Query:

If you specify the CAML statement, you can use the U2U tool to directly generate the CAML statement and copy it! This is the key because there are so many data retrieval settings. In the code above, the list and list items whose task status is "incomplete" are retrieved.

Query. RowLimit

Set the number of returned results, query. RowLimit = 10; set to return only 10 rows of data

 

BaseTypeThe following values can be entered:

Value Range Remarks
0 Generic list  
1 Document library  
3 Discussion forum  
4 Vote or Survey  
5 Issues list  

 

ServerTemplate can be set to the following values:

Determine the value of ServerTemplate.

1. In the Lists attribute topic of the SDK of WSS3.0, you can find a series of available list types.

2. Find the template file of the corresponding List under the feature file and view the value of the Type attribute.
For example, you can view that the ServerTemplate of the Announcements list is 104 through the following file:
(C: \ Program Files \ Common Files \ Microsoft Shared \ web server extensions \ 12 \ TEMPLATE \ FEATURES \ AnnouncementsList \ ListTemplates \ Announcements. xml)

3 Reference: http://egrimmett.wordpress.com/2008/04/01/servertemplate-numbers/

100 Generic list
101 Document library
102 Survey
103 Links list
104 Announcements list
105 Contacts list
106 Events list
107 Tasks list
108 Discussion board
109 Picture library
110 Data sources
111 Site template gallery
112 User Information list
113 Web Part gallery
114 List template gallery
115 XML Form library
116 Master pages gallery
117 No-Code Workflows
118 Custom Workflow Process
119 Wiki Page library
120 Custom grid for a list
130 Data Connection library
140 Workflow History
150 Gantt Tasks list
200 Meeting Series list
201 Meeting Agenda list
202 Meeting Attendees list
204 Meeting Decisions list
207 Meeting Objectives list
210 Meeting text box
211 Meeting Things To Bring list
212 Meeting Workspace Pages list
300 Portal Sites list
301 Blog Posts list
302 Blog Comments list
303 Blog Categories list
850 Page Library
1100 Issue tracking
1200 Administrator tasks list
2002 Personal document library
2003 Private document library

 

Http://blog.thekid.me.uk/archive/2007/02/27/spsitedataquery-samples-for-wss-v3.aspx:

Http://www.cnblogs.com/Kenr/archive/2009/06/02/1494260.html

For more information about SPSiteDataQuery, see MSDN: http://msdn.microsoft.com/zh-cn/library/microsoft.sharepoint.spsitedataquery.aspx.

 

Technorati tags: moss, SPSiteDataQuery, ServerTemplate, BaseType

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.