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