SPSiteDataQuery is used to Query multiple lists or to read data from all the lists in
a site collection.
![]() |
Get Combined result |
Below is the example to query multiple list data
sources and get combined information in data table:
{
using (SPWeb web = site.OpenWeb())
{
// Fetch using SPSiteDataQuery
SPSiteDataQuery query = new SPSiteDataQuery();
query.Lists = "<Lists MaxListLimit=\"5\">" +
"<List ID=" + web.Lists.TryGetList("Announcements").ID + " />" +
"<List ID=" + web.Lists.TryGetList("Content and Structure Reports").ID + " />" +
"<List ID=" + web.Lists.TryGetList("NavigationList").ID + " />" +
"<List ID=" + web.Lists.TryGetList("Reusable Content").ID + " />" +
"</Lists>";
query.ViewFields = "<FieldRef Name=\"Title\" />";
query.Webs = "<Webs Scope=\"Web\" />";
//Write appropriate query
query.Query = "";
query.RowLimit = 10;
//Convert result collection to data table
DataTable dataTable = web.GetSiteData(query);
}
}
Reference:
No comments:
Post a Comment