I am writing a feature receiver. At first I create some pages in "Site Pages" Library on feature activation and further I try to set one of the recently created page as Welcome page. But on deployment of the feature all works as intended except the welcome page. It remains the default "Home.aspx" under "Site Pages". The site where I deploy my feature is not a publishing site. Any specific reason?

Here is my sample code

 public void SetHomePage(SPWeb web, string path)

    if (PublishingWeb.IsPublishingWeb(web))
      PublishingWeb publish = PublishingWeb.GetPublishingWeb(web);
      SPFile file = web.GetFile(path);
      publish.DefaultPage = file;
      web.RootFolder.WelcomePage = path;

  • What code did you use to try to set teh welcome page? – Russell Aug 16 '12 at 7:44
  • I have edited my question for sample code.Please have a look. – V.B Aug 16 '12 at 7:54
  • 1
    Try removing "web.Update();" below the "pub.Update();". Perhaps the web.Update() is replacing teh DefaultPage property... – Russell Aug 16 '12 at 7:57
  • 1
    Does it work for non-publishing pages? Which were you trying? – Russell Aug 16 '12 at 7:58
  • Mine is not a publishing site. – V.B Aug 16 '12 at 8:01

Check the site you are using is a publishing site. Also remember if a site has already been used, users may have added bookmarks which will point directly to the old page. Make sure you consider the change management component if applicable.

Gary Lapointe has an article on how to set the default "welcome" page for publishing sites:


To summarise the code:

SPWeb web; // assuming you have an SPWeb object already.
SPFile file; // assuming you have an instance of SPFile for the page to set to be default.
PublishingWeb currentPublishingWeb = pubWeb;
currentPublishingWeb.DefaultPage = file;

If the site is not a publishing site, this MSDN article explains the SPFolder.WelcomePage property: http://msdn.microsoft.com/en-us/library/microsoft.sharepoint.spfolder.welcomepage.aspx

Here's the example:

using (SPSite oSiteCollection = new SPSite("http://MyServer/sites/MyWikiSite"))
    SPWeb oWebsite = oSiteCollection.OpenWeb();
    SPFolder oFolder = oWebsite.RootFolder; 
    oFolder.WelcomePage = "My Wiki Library/MyWelcome.aspx";

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.