fbpx

January 12, 2012

Get SharePoint 2010 Publishing Site Page Layout Programmatically

Get SharePoint 2010 Publishing Site Page Layout Programmatically

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);
}
}
}
  • Related Tags:

Leave a comment