Create a New Welcome page programmatically

The following code sample creates a new publishing page in a sub site in MOSS and set it to be the welcome page for the sub site. By providing the pagelayout, it knows which content type to use to create the publishing page.

private void CreateNewWelcomePage(SPWeb web, PageLayout pageLayout)
{
if (PublishingWeb.IsPublishingWeb(web))
{
PublishingWeb pubWeb = PublishingWeb.GetPublishingWeb(web);
PublishingPage welcomePage = pubWeb.GetPublishingPages().Add("Welcome.aspx", pageLayout);
welcomePage.Title = "Welcome Page";
welcomePage.Update();
welcomePage.CheckIn("Initial version");
pubWeb.DefaultPage = welcomePage.ListItem.File;
pubWeb.Update();
}
}

Comments

Ivan said…
this doesn't work

Popular posts from this blog

SharePoint 2013 App Details Page Error

SharePoint 2013 - Working with Display Template for Content Search Web Part

SharePoint 2013 Features Information List