Sunday 18 September 2011

Get all Pages in a Publishing site in Sharepoint


To get all the Publishing Pages in SharePoint you can use the '850' list template in your SPSiteDataquery. List Template Id 850 represents Pages library in your Publishing site.

example -
SPSiteDataQuery query = new SPSiteDataQuery();

//query Pages libraries
query.Lists = "<lists ServerTemplate='850' />";

query.ViewFields = "<fieldref Name='Title' /><fieldref Name='ID' />";

query.Webs = "<webs Scope='Recursive' />";

DataTable dt = SPContext.Current.Web.GetSiteData(query);
foreach (DataRow row in dt.Rows)
{
string content = string.Empty;

using (SPWeb web = SPContext.Current.Site.OpenWeb())
{
SPList pageslib = web.Lists["Pages"];
SPListItem _page = pageslib.GetItemById(int.Parse(row["ID"].ToString()));

content = _page["PublishingPageContent"].ToString(); -> gets the content on the Publishing Page.
}
}

Ads by Google

No comments:

Post a Comment