The below is
the code to change the page layout programatically of a publishing site
at the time of site creation in SharePoint 2010.
public override void WebProvisioned(SPWebEventProperties properties)
{
base.WebProvisioned(properties);
try
{
if (PublishingWeb.IsPublishingWeb(properties.Web))
{
PublishingWeb curPubWeb = PublishingWeb.GetPublishingWeb(properties.Web);
foreach (PageLayout curLayout in curPubWeb.GetAvailablePageLayouts())
{
if (curLayout.Name == "yourpagelayoutname.aspx")
{
foreach (PublishingPage curPage in curPubWeb.GetPublishingPages())
{
curPage.CheckOut();
curPage.Layout = curLayout;
curPage.Update();
curPage.CheckIn("");
}
break;
}
}
}
}
catch (Exception ex)
{
/* Handle exception here */
}
}
No comments:
Post a Comment