Scenario:
You need to query cross-list items across multiple Web sites
Solution:
'SPSiteDataQuery' is more efficent for such a situation.
'SPQuery' should be used to query a particular list
Sample Code:
SPWeb webSite = SPContext.Current.Web;
SPSiteDataQuery query = new SPSiteDataQuery();
query.Lists = "<Lists ServerTemplate=\"107\" />";
query.Query = "<Where><Eq><FieldRef Name=\"Status\"/>" +
"<Value Type=\"Text\">Completed</Value></Eq></Where>";
System.Data.DataTable items = webSite.GetSiteData(query);
foreach (System.Data.DataRow item in items)
{
Response.Write(SPEncode.HtmlEncode(item["Title"].ToString()) + "<BR>");
}
2 comments:
If I want to get join data from multiple lists in single site using CAML, then how it is possible?
you will need to add logic to go through multiple site collections and display it or load it in data table to be able to bind it to some control
Post a Comment