Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

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

share|improve this question

2 Answers 2

up vote 3 down vote accepted

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);
share|improve this answer

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

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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