Get SharePoint 2010 Publishing Site Page Layout Programmatically

12. January 2012 03:54 by Rashid Aziz in Sharepoint blogs  //  Tags: , ,   //   Comments

I have come across a business requirement, while implementing this I need to get publishing site page layout on sharepoint 2010 using server object model.

After a little research I managed to do this, I think it is worth to share code with you guys.

The code below was used to get the default page layout of a publishing web site in SharePoint 2010.

private static void GetPageLayout()
{
using (SPSite site = new SPSite("Publishing Site Collection URL"))
{
using (SPWeb web = site.OpenWeb())
{
PublishingWeb publishingWeb = PublishingWeb.GetPublishingWeb(web);

PageLayout pageLayout = publishingWeb.DefaultPageLayout;
Console.WriteLine("Layout Name: "+pageLayout.Name + " Site URL: " + pageLayout.ServerRelativeUrl);
}
}
}

 

blog comments powered by Disqus

Stay connected

SharePoint Links

Month List