ﻁ DevExpertise » Blog Archive » Setting the Welcome Page in WSS 3.0

DevExpertise

Practical tips and tricks for all things .NET, SharePoint, Silverlight, InfoPath, and general application development.

  • viagra kaufen apotheke cialis dove comprarlo viagra rezept online
  • kamagra aus indien sildenafil ohne rezept kamagra en pharmacie acheter levitra pas cher kamagra quanto costa farmacia viagra pharmacie france http://msh.univ-tours.fr/site_genre/wp-a... cialis prix en pharmacie viagra generique livraison rapide europe
    le viagra en pharmacie 
    prix du cialis 10 
    viagras pour femme 
    acheter silagra 100 sites fiables kamagra viagra forum
    apoteket viagra apotek viagra http://www.cricyt.edu.ar/?cmJ=G3835&cmC=...

    Setting the Welcome Page in WSS 3.0

    Posted by DevExpert on February 2nd, 2009

    Whenever someone navigates to your SharePoint site without a specific page specified in the URL, such as http://fakeserver/sites/fakesite/, SharePoint navigates you to the site’s welcome page, typically default.aspx.  MOSS publishing sites provide the ability to change this by going to Site Settings > Welcome Page, and changing the page.  What about team sites, or WSS sites?  There is no way to modify the welcome page through the UI.  One could open SharePoint Designer and do it that way, but this isn’t ideal if you don’t have a license for SPD.  I’ll be describing another approach in this post that leverages the Object Model, and I’m even providing a complete SharePoint solution (WSP) file that you can install and activate on any WSS site!

    First, let’s take a look at the code snippet to make this happen.  The SPFolder object has a property called WelcomePage, and all that is needed is to set this property on the SPWeb’s RootFolder:

    using (SPSite siteCollection = new SPSite(http://server/sites/sandbox)) {
        using (SPWeb site = siteCollection.RootWeb) {
            SPFolder rootFolder = site.RootFolder;
            rootFolder.WelcomePage = "Pages/home.aspx";
            rootFolder.Update();
        }
    }


    Now, whenever I hit http://server/sites/sandbox, I am directed to my custom Home.aspx page in my Pages document library:

    image


    Woo hoo!  If I click on the Sandbox title or its icon, or even in the breadcrumb, I’m directed here, because it’s to the site’s root URL, not to a specific page.  But what if I click the Home link on the top navigation bar? It takes me to my original default.aspx page, which defeats the purpose.  To fix this, we need to add the following lines of code:

    SPNavigationNode homeNode = site.Navigation.TopNavigationBar.Navigation.Home;
    homeNode = site.Navigation.TopNavigationBar[0];
    homeNode.Url = SPUrlUtility.CombineUrl(site.Url, "Pages/home.aspx");
    homeNode.Update();


    Now, no matter what I click to bring me back to the root page, I’m directed to my home.aspx page.  Who said the Welcome Page was a MOSS-only feature?

     

    SharePoint Solution

    It doesn’t make sense to expect an end user to run a console app or write custom code to do this.  It’s possible to do this via SharePoint designer too, but what if they don’t have it?  It makes a lot more sense to present this to users in the browser, exactly like a MOSS publishing site.  To provide this functionality, it’s just as simple as creating a custom LAYOUTS page and a solution package that can be used to deploy and install it. 

    First, we create the file-system structure in the Visual Studio solution:

    image


    Next, define the feature:

    <?xml version="1.0" encoding="utf-8"?>
    <Feature
      Id="2D3BDDCF-E6A4-4110-922C-70E79652C6B9"
      Title="DevExpertise Welcome Page Feature"
      Description="Contains the page and shortcuts to change a site's welcome page"
      Version="1.0.0.0"
      Scope="Site"
      Hidden="false" 
      ImageUrl="DevExpertise.WelcomePage\devExpertiseFeatureLogo.png" 
      xmlns="http://schemas.microsoft.com/sharepoint/">
      <ElementManifests>
        <ElementManifest Location="CustomActions.xml" />
      </ElementManifests>
    </Feature>


    The custom action should be defined to add a link to the Look & Feel category (GroupId=”Customization”):

    <?xml version="1.0" encoding="utf-8" ?>
    <Elements xmlns="http://schemas.microsoft.com/sharepoint/">
      <CustomAction
        Id="UserGroupAdminLinkForSettings"
        GroupId="Customization"
        Location="Microsoft.SharePoint.SiteSettings"
        RequireSiteAdministrator="TRUE"
        Sequence="120"
        Title="Welcome Page">
        <UrlAction Url="_layouts/DevExpertise.WelcomePage/WelcomePage.aspx" />
      </CustomAction>
    </Elements>
    


    Package up your solution using WSPBuilder and deploy it.  After it’s deployed and activated on the site collection, I’m presented with a Welcome Page link on each and every sub site in the site collection, allowing me to set the welcome page for each site:

    image


    Clicking the link will navigate to the custom LAYOUTS page I created:

    image


    This is a great method for providing functionality that may be missing from the user interface.  Once you master the steps required to create a LAYOUTS page (which I’ll be covering step-by-step in a future post), and master creating custom actions, the possibilities to extend and enhance your SharePoint site are endless.

    I’ve included this solution package for you to deploy and use.  As always, the code is as-is and without warranty, so if it doesn’t work – fix it!

    Download Solution: DevExpertise.WelcomePage.zip

    3 Responses to “Setting the Welcome Page in WSS 3.0”

    1. Joshua Eastlund Says:

      Hi, I found this post while looking for help with Microsoft Silverlight. I have recently changed internet browser from Google Chrome to Mozilla Firefox 3.1. After the change I seem to have a issue with loading sites that have Microsoft Silverlight. Everytime I browse page that requires Microsoft Silverlight, my browser freezes and I get a “npctrl.dll” error. I can’t seem to find out how to fix the problem. Any help getting Microsoft Silverlight to function is very appreciated! Thanks

    2. Scott Says:

      Hey there…I have been messing with the code you provided, and first wanted to say thanks for this. It definitely pointed me in the right direction. However, this only works for setting a site collection’s home page, yet the link shows up in the Look and Feel area for each of the sub sites. When you use the page in a sub-site, it still sets the site collection’s home page. I am messing with it right now, and have added the functionality in a feature receiver to set the site collection back to default.aspx upon deactivation, and also to look at all child webs and set them back to default.aspx, but am still haven’t found the proper context to have this only work at the site level instead of the site collection level.

      Thanks again, and if you have any ideas on how to change this, please let me know (or if you want the code I am using for the feature deactivation, although it is pretty simple).

      Scott

    3. Elli Sarkar Says:

      it’s very nice icon set’s. subscribe to rss.. thank u..;)

    Leave a Reply

    XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>