2

I would like to change my default welcome page on my web, but I would like to avoid activation of feature "Publishing web" on my web just for that small requirement (with that approach I'm familiar).

My custom page is deployed via module (and modul is deployed via feature) and reside in database.

Any suggestion, please?

2
  • 1
    you deploy a file under _layouts with a module ?
    – Steve B
    Commented Aug 31, 2011 at 9:35
  • Sorry, i think they gone to database directly. My mistake.
    – trip
    Commented Aug 31, 2011 at 10:29

6 Answers 6

7

You can do this in code: Set the Welcome Page property of the RootFolder of a web. This property is available in 2007 and 2010

using (SPSite oSiteCollection = new SPSite("http://MyServer/sites/MySubSite")){  
  using(SPWeb oWebsite = oSiteCollection.OpenWeb()){
    SPFolder oFolder = oWebsite.RootFolder; 
    oFolder.WelcomePage = "_layouts/MyFeature/MyWelcome.aspx";
    oFolder.Update();
  }
}

See also http://msdn.microsoft.com/en-us/library/microsoft.sharepoint.spfolder.welcomepage(v=office.12).aspx

2

If you are working with SP2010, you can activate the "Default page as wiki" feature, then, on a specific page, you can click on "set as default page".

However, you said the page resides under _layouts... this approach implies you provision your page as a wiki page.

1
  • Sorry they gone to database directly, not in _layouts. My mistake.
    – trip
    Commented Aug 31, 2011 at 10:30
0

You can do this with code. This was on a WSS 3.0 instance, so no publishing feature available. I have a project that placed my site pages into a document library. On the FeatureActivation method, I have the following code.

   using (SPWeb web = (SPWeb)properties.Feature.Parent)
   {
       siteUrl = web.Url;
       web.Navigation.Home.Url = "pages/home.aspx";
       web.Update();
   }
2
  • Unfortunately this won't work in SP2010. I even tried to add web.allowunsafeupdates = true and web.Navigation.Home.Update(); but it didn't helped.
    – trip
    Commented Aug 31, 2011 at 10:21
  • 1
    Can you deploy the page to the SitePages Doc Lib? Pages in this location have a "Make Homepage" button in the ribbon for Page.
    – Rich Ross
    Commented Aug 31, 2011 at 11:23
0

Set the WelcomePage property of the RootFolder object of the SPWeb object (don't forget to call Update).

That will only work for relative urls which point to a page in a sharepoint list.

0

Setting custom home URL without enabled SharePoint publishing site feature:

var folder = Web.RootFolder;
folder.Properties["vti_welcomepage"] = "SitePages/MyStartPage.aspx?mode=1";
folder.Update();

!Do not execute Web.Update() afterwards, dispose SPWeb.

-2

After investigation, conclusion is that there isn't more elegant solution (except activate Publishing web feature, and than define via code) than - deploy page, navigate to page via browser, open page tab on ribbon, and click "Make Homepage" button. And problem solved.

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.