Click here to Skip to main content
Click here to Skip to main content

Shared Navigation for SharePoint Site Collections

By , 29 May 2009
 

Introduction

By now you have already noticed there is no out-of-the-box way in SharePoint to have more than one site collection sharing the same top navigation. I hope that’s why you are here, because this is what this code is about.

Shared navigation for site collections is a very desirable feature in scenarios where, for example, you create a site collection for each department in your organization and place them under a parent site collection. Many organizations choose to create a site collection for each department, due to security concerns or to better manage the content databases. So, they want them to be isolated but at the same time share the same navigation.

This article is about a SharePoint navigation provider I wrote, that lets you borrow the top navigation from a specified site collection. This way you can have unlimited number of site collections sharing the same navigation.

First, I will show you how to implement and use the navigation provider, and later, I'll dive briefly into the code. Let's start with:

How Does it Work

SharedNavigationProvider is a navigation provider. It has to be registered in web.config, and has a parameter to indicate the source site collection for navigation. The provider will parse the navigation of the indicated source site collection and prepare it for the current site. The AspMenu control in the default master page will need to be modified to use the data source from SharedNavigationProvider.

How to Install and Use

There is no installation package or feature yet, but I do plan to create them when time permits. So, for now, installation instruction is a list of steps to modify the web.config and the master page.

There are two major requirements:

  1. All site collections must be on the same farm. They can be part of different applications, or part of the same application, but must be on the same farm.
  2. All webs implementing this navigator must have the Office SharePoint Server Publishing feature activated.

And, there are three major steps for installation:

  1. Add the DLL to the GAC
  2. Add the navigation provider to the web.config
  3. Modify the master page to use SharedNavigationProvider

1. Add the DLL to the GAC

  • I added a small .bat file, AddToGAC.bat, to the root of the project that does just that.
  • I am assuming you have gacutil.exe in c:\Program Files\Microsoft Visual Studio 8\SDK\v2.0\Bin\. If not, you should find a way to get it. (For more info about gacutil, please see: http://msdn.microsoft.com/en-us/library/ex0ss12c(VS.85).aspx).
  • You must repeat this step on all front web servers.

2. Add the Navigation Provider to the web.config

  • Locate the web.config of your site collection (actually of your web application) and add the following provider entry:
  • <!-- ... -->
    <system.web>
        <siteMap >
            <providers>
            <!-- ... -->
            <add name="SharedNavigationProvider" 
               SourceSite="http://SourceSiteCollection" 
               NavigationType="Global" EncodeOutput="true" 
               type="DataQ.SharePoint.Providers.SharedNavigationProvider, 
                     SharedNavigationProvider, Version=1.0.0.0, 
                     Culture=neutral, PublicKeyToken=fc448b9e121af773" />
            </providers>
    <!-- ... -->
    
  • Set the SourceSite parameter to be the URL of the source site collection from where you want to borrow the navigation.
  • Repeat this step on all front web servers, if you have more than one.

3. Modify the Master Page to Use SharedNavigationProvider

Your master page needs to be modified to use the provider. You can do this in more than one way. You may use SharePoint Designer, or you may download the file, modify it, then upload, publish, and approve it. I don't think it is necessary to elaborate on that, but if you feel I should, drop me a message, and I'll do.

I will describe here what you need to change once you have the default.master (or whatever.master page you have set for your site) file opened.

  1. Be sure you keep a backup copy of the master page you are going to change.
  2. Be sure you are doing 1.
  3. Open the master page in your HTML editor of choice.
  4. Locate this control: <SharePoint:DelegateControl runat="server" ControlId="TopNavigationDataSource">, and underneath it, place this control:
  5. <asp:SiteMapDataSource 
        ShowStartingNode="False"
        SiteMapProvider="SharedNavigationProvider"
        id="topSiteMap2"
        runat="server"/>
  6. Locate this control: <SharePoint:AspMenu ID="TopNavigationMenu" ….. You should find it above the control we modified in 4.
  7. Change the attributes DataSourceID to topSiteMap2 and StaticDisplayLevels to 1:

    DataSourceID="topSiteMap2"
    StaticDisplayLevels="1"
  8. If you use the out-of-the-box default.master page, all these changes should look like this:
  9. <SharePoint:AspMenu
          ID="TopNavigationMenu"
          Runat="server"
          DataSourceID="topSiteMap2"
          EnableViewState="false"
          AccessKey="<%$Resources:wss,navigation_accesskey%>"
          Orientation="Horizontal"
          StaticDisplayLevels="1"
          MaximumDynamicDisplayLevels="1"
          DynamicHorizontalOffset="2"
          StaticPopoutImageUrl="/_layouts/images/menudark.gif"
          StaticPopoutImageTextFormatString=""
          DynamicHoverStyle-BackColor="#CBE3F0"
          SkipLinkText=""
          StaticSubMenuIndent="0"
          CssClass="ms-topNavContainer">
            <StaticMenuStyle/>
            <StaticMenuItemStyle CssClass="ms-topnav" ItemSpacing="0px"/>
            <StaticSelectedStyle CssClass="ms-topnavselected" />
            <StaticHoverStyle CssClass="ms-topNavHover" />
            <DynamicMenuStyle  BackColor="#F2F3F4" 
              BorderColor="#A7B4CE" BorderWidth="1px"/>
            <DynamicMenuItemStyle CssClass="ms-topNavFlyOuts"/>
            <DynamicHoverStyle CssClass="ms-topNavFlyOutsHover"/>
            <DynamicSelectedStyle CssClass="ms-topNavFlyOutsSelected"/>
        </SharePoint:AspMenu>
            
    <SharePoint:DelegateControl runat="server" 
              ControlId="TopNavigationDataSource">
        <Template_Controls>
            <asp:SiteMapDataSource
              ShowStartingNode="False"
              SiteMapProvider="SPNavigationProvider"
              id="topSiteMap"
              runat="server"
              StartingNodeUrl="sid:1002"/>
        </Template_Controls>
    </SharePoint:DelegateControl>
    
    <asp:SiteMapDataSource 
      ShowStartingNode="False"
      SiteMapProvider="SharedNavigationProvider"
      id="topSiteMap2"
      runat="server"/>
  10. When you upload the modified master page, don’t forget there are three important steps to follow:
    1. Check in
    2. Publish as a Major Version
    3. Approve the new master page

The Code

I am not going to comment a lot here about the code inside this article, but I ensure you the code itself is well commented. So, if you plan to change it, you should find helpful hints about what I am doing.

In short, the idea of the navigation provider is to parse the source navigation structure and provide it as a dataset to the destination site collection.

Known Issues

  • The target attribute in the source navigation is not honored in the replicated navigations. This is something I plan to change in the next version.
  • There is an issue with navigation caching when you enable the source site collection to display subsites. When you add new subsites, it will not show right away in the shared navigation. To get around this, you should just move up and down the node in the source navigation and the caching is fixed.

What's Next

The code, of course, can be improved:

  • It can use smarter caching
  • It can add an admin page to the Site Sittings to set the source site collection
  • All installation steps can be automated and packaged into a solution package.

History

  • May 29th, 2009 - Published.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

About the Author

Marian Dumitrascu
Architect Data Quadrant, Inc.
United States United States
Member
Seek, create and combine solutions in the realm of Information Portals, Business Inteligence and Business Automation. With a focus on SharePoint. (Houston, TX)

Sign Up to vote   Poor Excellent
Add a reason or comment to your vote: x
Votes of 3 or less require a comment

Comments and Discussions

 
Hint: For improved responsiveness ensure Javascript is enabled and choose 'Normal' from the Layout dropdown and hit 'Update'.
You must Sign In to use this message board.
Search this forum  
    Spacing  Noise  Layout  Per page   
QuestionWorks for 2010 BUT Subsite drop-down does not extend all the levelsmemberAbhrajit_d3 Jul '12 - 10:30 
QuestionSites vs links in navigationmemberPhilip.izod31 Oct '11 - 2:26 
GeneralThank you. Navigation is working for 2010 site collections also.. [modified]memberAnuMattamudhre19 May '11 - 2:45 
GeneralFeature was requested too... thank you [modified]memberSandro Mueller26 Apr '11 - 5:09 
GeneralThere's a great solution that based on the same Ideamemberbob.cedric15 Jun '10 - 8:03 
Generalsub menu in navigation not showing upmembermyhiding24 May '10 - 10:31 
GeneralShared Navigation for SharePoint Site Collections is not working in my sitecollectionmembergoutam kumar Chak10 Mar '10 - 4:37 
GeneralRe: Shared Navigation for SharePoint Site Collections is not working in my sitecollectionmemberChristopher TS16 Mar '10 - 18:00 
GeneralAudience TargetingmemberMember 17229825 Mar '10 - 8:55 
GeneralSecurity TrimmingmemberMember 28654849 Feb '10 - 0:38 
GeneralRe: Security TrimmingmemberMarian Dumitrascu10 Feb '10 - 5:05 
GeneralYOU ARE A GENIUSmemberrutuma11 Dec '09 - 10:15 
QuestionCan this work across web applicationsmemberjte36925 Sep '09 - 4:56 
Generalcustomized header linksmembermbruni.mka2 Sep '09 - 9:55 
GeneralCannot get this working on MOSS 2007 sp1membershikarishambu7031 Jul '09 - 8:54 
GeneralRe: Cannot get this working on MOSS 2007 sp1memberMarian Dumitrascu31 Jul '09 - 9:29 
GeneralRe: Cannot get this working on MOSS 2007 sp1memberwebwyse3 Sep '09 - 11:45 
GeneralRe: Cannot get this working on MOSS 2007 sp1memberDhruv198410 Dec '09 - 2:54 
GeneralWSSmemberJason L12 Jun '09 - 7:25 
GeneralRe: WSSmemberMarian Dumitrascu12 Jun '09 - 7:29 
GeneralRe: WSSmemberjelliotboston16 Oct '09 - 12:11 
GeneralRe: WSSmemberMarian Dumitrascu16 Oct '09 - 13:32 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Permalink | Advertise | Privacy | Mobile
Web03 | 2.6.130516.1 | Last Updated 29 May 2009
Article Copyright 2009 by Marian Dumitrascu
Everything else Copyright © CodeProject, 1999-2013
Terms of Use
Layout: fixed | fluid