I have a web part to retrieve list items recursively from different subsites. I used SPSiteDataQuey like the code in below. this code retrieve the required data when I add this webpart to the root web, but when add it to a subsite under the root web, it could not retrive the data from the subsites under that subsite :)
This is the code:
private DataView GetTasks()
{
using (SPWeb spWeb = SPContext.Current.Site.OpenWeb(SPContext.Current.Web.ID))
{
string query = "<OrderBy>" +"<FieldRef Name=\"Title\" />" +"</OrderBy>";
SPSiteDataQuery spDataQry = new SPSiteDataQuery();
//Querying all Task Lists from the current site and its childs
spDataQry.Lists = "<Lists ServerTemplate=\"20123\" />";
spDataQry.ViewFields = "<FieldRef Name=\"Title\" />" +"<FieldRef Name=\"TaskStatus\" />" +"<FieldRef Name=\"AssignedTo\" />" +"<FieldRef Name=\"StartDate\" />" +"<FieldRef Name=\"TaskDueDate\" />" +"<FieldRef Name=\"FileRef\" />";
spDataQry.Query = query;
spDataQry.Webs = "<Webs Scope=\"Recursive\" />";
DataTable dtTaskList = spWeb.GetSiteData(spDataQry);
DataView dvTasksList = new DataView(dtTaskList);
return dvTasksList;
}
}Any help please?