Click to Rate and Give Feedback
SPSiteDataQuery Class (Microsoft.SharePoint)
Describes a query performed across multiple lists, which may be located in multiple Web sites in the same Web site collection.

Namespace: Microsoft.SharePoint
Assembly: Microsoft.SharePoint (in microsoft.sharepoint.dll)

Visual Basic (Declaration)
<SharePointPermissionAttribute(SecurityAction.InheritanceDemand, ObjectModel:=True)> _
<SharePointPermissionAttribute(SecurityAction.LinkDemand, ObjectModel:=True)> _
Public NotInheritable Class SPSiteDataQuery
Visual Basic (Usage)
Dim instance As SPSiteDataQuery
C#
[SharePointPermissionAttribute(SecurityAction.InheritanceDemand, ObjectModel=true)] 
[SharePointPermissionAttribute(SecurityAction.LinkDemand, ObjectModel=true)] 
public sealed class SPSiteDataQuery

This example performs a query against all document libraries in a particular Web site and returns the file paths for the items whose ID is greater than 1.

C#
SPWeb oWebsite = SPContext.Current.Web;
SPSiteDataQuery oQuery = new SPSiteDataQuery();
string strWhere = "<Where><Gt>" +
    "<FieldRef Name=\"ID\" />" +
    "<Value Type=\"Number\">1</Value>" + 
    "</Gt></Where>";

string strOrderBy = "<OrderBy><FieldRef Name=\"FileRef\" /></OrderBy>";

oQuery.Query = strWhere + strOrderBy;

oQuery.Lists = "<Lists ServerTemplate=\"101\" />";
oQuery.ViewFields = "<FieldRef Name=\"Title\" />";
 
DataTable dtResults = oWebsite.GetSiteData(oQuery);
System.Object
  Microsoft.SharePoint.SPSiteDataQuery
Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.
Tags What's this?: Add a tag
Community Content   What is Community Content?
Add new content RSS  Annotations
.Net SqlClient Data Provider exception when adding EventDate into ViewFields with Nullable = true.      JeffLin   |   Edit   |  

If you are getting the following exception when running SPSiteDataQuery, you may want to check if you have any of the following three fields types in your <ViewFields> element.

  1. Lookup field
  2. Person or Group field
  3. a field called EventDate

The root cause for the above three fields is that the back-end query into SQL, that needs to return one than one columns for any of the three site fields(columns), is constructed to return a few more other columns from DB. However, the Nullable setting only mark one of the many fields into allowing NULL values. There is nothing we can do on # 1 or 2, but for #3, we will have to add a few more fields to avoid the problem.


<ViewFields>
<FieldRef Name="EventDate" Nullable="TRUE" />
<FieldRef Name="fAllDayEvent" Nullable="TRUE" />
<FieldRef Name="EndDate" Nullable="TRUE" />
<FieldRef Name="TimeZone" Nullable="TRUE" />
<FieldRef Name="XMLTZone" Nullable="TRUE" />
</ViewFields>
Tags What's this?: Add a tag
Flag as ContentBug
Limitations of the SPSiteDataQuery      smc750   |   Edit   |  

Please see the following Knowledgebase article on the limitations of the SPSiteDataQuery.

http://support.microsoft.com/kb/946484

Tags What's this?: Add a tag
Flag as ContentBug
EndDate also needs additional fields      SPDev   |   Edit   |  

If you want to return the built-in EndDate field (not to be confused with "_EndDate") you will also need to return the group of fields listed above. Otherwise, SP will throw a COM exception which doesn't point to the source of the problem. I.e.,

<ViewFields>
<FieldRef Name="EventDate" Nullable="TRUE" />
<FieldRef Name="fAllDayEvent" Nullable="TRUE" />
<FieldRef Name="EndDate" Nullable="TRUE" />
<FieldRef Name="TimeZone" Nullable="TRUE" />
<FieldRef Name="XMLTZone" Nullable="TRUE" />
</ViewFields>

Interestingly, if you use "_EndDate" instead of "EndDate", your query will return rows instead of blowing up but the EndDate will always return an empty string.

See the post "SP Field Dependencies" at the bottom of http://msdn.microsoft.com/en-us/library/microsoft.sharepoint.spbuiltinfieldid.enddate.aspx for why all 5 fields are required.

Tags What's this?: Add a tag
Flag as ContentBug
Processing
© 2008 Microsoft Corporation. All rights reserved. Terms of Use  |  Trademarks  |  Privacy Statement
Page view tracker