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

See More Articles

Contact us

To begin your digital transformation, get in touch.

We’re pleased to address any inquiries you might have and assist you in selecting the service that best suits your requirements.

Your benefits:
Speak To Us