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


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);

if you need to Query the siteCollection you need to use SPSiteDataQuery

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.