4

I need to set the homepage to default.aspx in my FeatureActivated event receiver. I tried

rootWeb.RootFolder.WelcomePage = "default.aspx";
rootWeb.RootFolder.Update();

but that doesn't seem to be working...this HAS to work in Sharepoint Foundation....i have seen some methods that are not compatible with foundation?

TIA

2 Answers 2

2

Please check this link to see how to set your home page.

If this does not work, please try to debug and check if your FeatureActivated event gets fired.

Hope this helps

Cheers!

My bad that I did not see that. Anyways can you please try below,

Please use this in feature activating,

SPWeb web = properties.Feature.Parent as SPWeb;
    if (web != null)
        {
            SPFolder rootFolder = web.RootFolder;
            rootFolder.WelcomePage = "YOURCUSTOMURLGOESHERE";
            rootFolder.Update();
        }
    }

If you would like to resort to your default page during feature deactivation, rootFolder.WelcomePage = "default.aspx";

4
  • SharePoint Foundation doesn't include publishing features hence the link you posted doesn't apply as it uses SharePoint Server features. Just FYIO.
    – Sig Weber
    Commented Oct 18, 2012 at 16:07
  • Yep...thats what i thought. There has to be a way to do this in Sharepoint Foundation short of replacing Home.aspx :P
    – MikeC
    Commented Oct 18, 2012 at 17:59
  • I have edited my original post, to achieve this. Commented Oct 19, 2012 at 1:15
  • 1
    Just a tip, don't put web in a using block. If you didn't create the SPWeb or SPSite using new, it's not yours to dispose! Also, I presume you meant SPFolder rootFolder = web.RootFolder?
    – MorayM
    Commented May 2, 2014 at 10:16
0

maybe slightly off-topic, but since SharePoint 2013 it is possible to set the homepage via the client-side object model (CSOM); one way to do that (which i think is very easy) is to use PnP-PowerShell - there is a PowerShell-cmdlet just to set the home page of a web:

Set-PnPHomePage

Please see https://github.com/SharePoint/PnP-PowerShell/blob/master/Documentation/SetPnPHomePage.md for details

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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