Tuesday, January 19, 2010

Query multiple lists across sites in a web site collection

Title: Query multiple lists across sites in a web site collection

Details: SPSiteDataQuery Class - This is one of the very intresting and wonderful classes available in SharePoint to retreive information from list across sites in the same web site collections. How many of you have tried the roll up ( not including the CQWP ) by coding? Look at the below code and see the simplicity of it. Simply build the SPSiteDataQuery ( query ) to the GetSiteData Method and get DataTable in return. One important thing to notice is that, it is not supported in SharePoint 2010 Sandboxed Solutions.

Code:

void UsingSPSiteDataQuery(SPWeb web)
{
   SPSiteDataQuery query = new SPSiteDataQuery();
            
   query.Lists = "";
   query.ViewFields = "";
   query.Webs = "";

   web.GetSiteData(query);
}

No comments: