I need to use API to return all Publishing pages using a specific content type in a publishing site. this includes querying all sites in the site collection. Can I do that with SPQuery?
I am using SharePoint 2010 / Visual Studio 2010
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It only takes a minute to sign up.Sign up to join this community
You have to use SiteDataQuery as replied by Thomson above.
Here is some sample code
SPWeb web = SPContext.Current.Site.RootWeb; SPSiteDataQuery query = new SPSiteDataQuery(); //Server template for page library is 850 query.Lists = "<Lists ServerTemplate='850' Hidden='TRUE' />"; query.ViewFields = @"<FieldRef Name='URL' Nullable='True' Type='URL' /><FieldRef Name='Title' Nullable='TRUE' Type='Text' />"; query.Webs = "<Webs Scope='Recursive' />"; query.Query = @"<Where><Eq><FieldRef Name='ContentType'/><Value Type='Text'>CT_Page_News</Value></Eq></Where>" DataTable dt = web.GetSiteData(query);