Changing the SharePoint Welcome Page Programmatically
Introduction:
Sometimes you will have a feature which you activate on a sub site where you want to change the “Welcome Page” or landing page to be a custom one.
Here is a sample on how you can change default.aspx to be a new page like welcome.aspx or home.aspx etc that you have just created.
The Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 | public static void ChangeWelcomePage(SPWeb rootWeb, string pageName) { if (PublishingWeb.IsPublishingWeb(rootWeb)) { PublishingWeb pubWeb = PublishingWeb.GetPublishingWeb(rootWeb); //Get the file name SPFile welcomeFile = rootWeb.GetFile(pageName); //Assign the new filename to the DefaultPage property pubWeb.DefaultPage = welcomeFile; //Update the Publishing Web. pubWeb.Update(); } } |
Thanks!
Avinash
June 20, 2012
В·
Infoyen В·
No Comments
Tags: MOSS, SharePoint В· Posted in: MOSS, SharePoint
Leave a Reply