In my previous post
, we have learned how to create custom page layouts using feature.
We need to set the custom page layout created as the default page layout of the site.
Say if a user creates a new page, it should create a page which is using the custom layout.
We need to achieve this programatically.
We can achieve this by writing the code within the receiver of the feature created.
public override void FeatureActivated(SPFeatureReceiverProperties properties)
SPSite site = properties.Feature.Parent as SPSite;
SPWeb web = null;
if (site == null)
web = properties.Feature.Parent as SPWeb;
if (web == null) return;
site = web.Site;
else web = site.RootWeb;
PublishingWeb objPublishingWeb = PublishingWeb.GetPublishingWeb(web);
//Set default page layout of site to internal page layout
if (objPublishingWeb != null)
PageLayout _pageLayout = (from _pl in objPublishingWeb.GetAvailablePageLayouts()
where _pl.Name == “InnerPage.aspx”