Translate

Monday, August 20, 2012

Querying Multiple Lists using SPSiteDataQuery

SPSiteDataQuery



SPSiteDataQuery is used to query multiple lists and SPQuery fetches only from single list
Sample code demonstrate
a query that returns events from all calendars
in the current site collection where the end date is later than Current Date

Sample Code:

SPSiteDataQuery query = new SPSiteDataQuery;

query.Query = "<Where><Gt><FieldRef Name='EndDate'/>" +
"<Value Type='DateTime'><Today OffsetDays=\"-1\"/></Value></Gt>
</Where>";

query.Lists = "<Lists ServerTemplate='106' />";
query.ViewFields ="<FieldRef Name='Title' />" ;
query.Webs = @"<Webs Scope='SiteCollection' />";
DataTable table = SPContext.Current.Site.RootWeb.GetSiteData(query);


No comments:

Post a Comment