After provisioning a site the new site does not have the right page layout like I instructed the code to be. I went to site settings of the new site and clicked on page layout and site template. And sure enough it was inheriting from parent instead of using what I told it to use. hmm. Can anyone see any fault in the code? The page layout pages shows in the list.
private static void AddPage(SPSite site, SPWeb web, string pageName, string strPageTitle)
{
PublishingWeb publishingWeb = PublishingWeb.GetPublishingWeb(web);
PageLayout[] pageLayouts = publishingWeb.GetAvailablePageLayouts();
PageLayout currPageLayout = null;
foreach (PageLayout pl in pageLayouts)
{
if (pl.Name.Equals("RMLayout.aspx", StringComparison.InvariantCultureIgnoreCase))
{
currPageLayout = pl;
break;
}
}
PublishingPageCollection pages = publishingWeb.GetPublishingPages();
PublishingPage newPage = pages.Add(pageName, currPageLayout);
publishingWeb.Update();
string content = ""; // "Welcome to <strong>My Page</strong>";
newPage.ListItem[FieldId.PublishingPageContent] = content;
newPage.Title = strPageTitle;
newPage.ListItem.Update();
newPage.Update();
newPage.ListItem.File.CheckIn("System Checkin");
newPage.ListItem.File.Publish("System Published");
}
newPage
?