Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

I am installing a sub-site in Sharepoint 2010 using PowerShell. For all the sub-sites, we have configured sharepoint to launch a particular sub-site's default.aspx page as landing page after log-in. For my use case, I want override this behavior by launching a page being created as a part of a Feature used in this sub-site. How can I do that? Please help...

share|improve this question
add comment

2 Answers

Kosty, you can set the welcome page via the WelcomePage property of the RootFolder of the new SPWeb that you're creating:

SPWeb web = GetYourSPWebObject();
web.RootFolder.WelcomePage = "/Pages/Landing.aspx";
web.Update();

If you are trying to achieve this with a page in the Layouts folder in the hive, see Redirect default.aspx or change default landing to page in _layouts folder?

You can place this code in your feature receiver to set the welcome page when the feature is activated (and to set it back when the feature is deactivated).

share|improve this answer
    
Thanks for the response. Initially there was no welcome page. Setting it up using the above mentioned method doesn't help. Seems like Welcome Page and Default Page are different. Is that so? –  Kosty Feb 5 '13 at 19:44
    
Do you mean PublishingWeb.DefaultPage? "Gets and sets the Welcome page for this PublishingWeb object." msdn.microsoft.com/en-us/library/… I don't know if they are or not. You could use reflector if you really wanted to know. If this is a PublishingWeb there is code in the MSDN link showing how to set this (but it's basically the same). –  RJ Cuthbertson Feb 5 '13 at 19:58
    
If the page is in the root of the SPWeb (not in the Pages library, etc.), you could set the RootFolder's welcome page to just the name of the page "Page.aspx" (no /'s). –  John Chapman Feb 5 '13 at 19:59
    
The page resides under the site. I have tried these ways already. It is not working. :( –  Kosty Feb 5 '13 at 20:26
    
I was able to achieve similar functionality via Feature's EventReciever. –  Kosty Feb 6 '13 at 15:38
show 1 more comment

Here's the code which worked for me. I put it in Feature's Event Reciever

public override void FeatureActivated(SPFeatureReceiverProperties properties)
    {
        using (var currentWeb = properties.Feature.Parent as SPWeb)
        {
            if (currentWeb != null)
            {
                var root = currentWeb.RootFolder;
                if (root != null)
                {
                    root.WelcomePage = @"Management\Pages\LandingPage.aspx";
                    root.Update();
                }

                //this.AddNavigationNodes(currentWeb);
            }
        }

        base.FeatureActivated(properties);
    }

However, my changes don't show up until I disable and then re-enable my feature. Is there a work around for this? Please let me know.

share|improve this answer
    
This is essentially the same as the code that I posted. If you have a new question, please post it as a separate thread. The sharepoint.stackexchange.com/faq provides a thorough explanation of the rules and expectations of SP-SE. Welcome to the site. –  RJ Cuthbertson Feb 6 '13 at 15:50
    
Of course your changes don't show up until you re-activate your feature - you put the changes into feature activate event :) –  Andrey Nov 13 '13 at 19:56
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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