1

I have been using a web template, based on STS#0, to programmatically create root site collections. There are now 10,000+ of these created over the years, and I have to update the default.aspx page.

I intend to do this a feature activated event receiver as follows:

public override void FeatureActivated(SPFeatureReceiverProperties properties)


         {
            SPSite site = properties.Feature.Parent as SPSite;
            using (SPWeb web = site.RootWeb)
            {
                SPFolder rootFolder = web.RootFolder;
                rootFolder.WelcomePage = "/SitePages/TestHomePage.aspx";
                rootFolder.Update();
            }
         } 

So each time a user opens a site collection, I can check if this feature has been activated, and then activate if necessary, using Farm properties to store the ID of feature (it is a full trust solution).

I have the new TestHomePage.aspx stored in a SitePages library that is part of each site collection, but each time the feature is activated, I just get the error:

"Application error when access /_layouts/15/ManageFeatures.aspx, Error=The WelcomePage property must be a path that is relative to the folder, and the path cannot contain two consecutive periods (..).

I have tried the following paths:

SitePages/TestHomePage.aspx
/SitePages/TestHomePage.aspx

Does anyone have an idea of what I am doing wrong?

  • PS I have also tried: Also tried: rootFolder.WelcomePage = "/Site Pages/TestHomePage.aspx"; and rootFolder.WelcomePage = "Site Pages/TestHomePage.aspx"; – Jimmy Aug 12 '16 at 16:29
1

"/SitePages/TestHomePage.aspx" will not work. You need to remove use "SitePages/TestHomePage.aspx". The below code should work

        SPSite site = properties.Feature.Parent as SPSite;
        using (SPWeb web = site.RootWeb)
        {
            SPFolder rootFolder = web.RootFolder;
            rootFolder.WelcomePage = "SitePages/Home.aspx";
            rootFolder.Update();
        }
  • I had done too much work on one site collection - I deleted the site collection, re-created it and then: rootFolder.WelcomePage = "Site Pages/TestHomePage.aspx"; worked OK. – Jimmy Aug 15 '16 at 14:33

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.