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

Shared Navigation for SharePoint Site Collections

, 29 May 2009 CPOL
Rate this:
Please Sign up or sign in to vote.
A SharePoint navigation provider for sharing top navigation with any site collection inside the same farm.

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)

Share

About the Author

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

Comments and Discussions

 
QuestionSharePoint 2013 PinmemberMember 1026781811-Sep-13 10:40 
AnswerRe: SharePoint 2013 PinmemberMember 1026781823-Jan-14 8:47 
QuestionWorks for 2010 BUT Subsite drop-down does not extend all the levels PinmemberAbhrajit_d3-Jul-12 11:30 
QuestionSites vs links in navigation PinmemberPhilip.izod31-Oct-11 3:26 
GeneralThank you. Navigation is working for 2010 site collections also.. [modified] PinmemberAnuMattamudhre19-May-11 3:45 
GeneralFeature was requested too... thank you [modified] [modified] PinmemberSandro Mueller26-Apr-11 6:09 
GeneralThere's a great solution that based on the same Idea Pinmemberbob.cedric15-Jun-10 9:03 
Generalsub menu in navigation not showing up Pinmembermyhiding24-May-10 11:31 
GeneralShared Navigation for SharePoint Site Collections is not working in my sitecollection Pinmembergoutam kumar Chak10-Mar-10 5:37 
GeneralRe: Shared Navigation for SharePoint Site Collections is not working in my sitecollection PinmemberChristopher TS16-Mar-10 19:00 
GeneralAudience Targeting PinmemberMember 17229825-Mar-10 9:55 
GeneralSecurity Trimming PinmemberMember 28654849-Feb-10 1:38 
GeneralRe: Security Trimming PinmemberMarian Dumitrascu10-Feb-10 6:05 
GeneralYOU ARE A GENIUS Pinmemberrutuma11-Dec-09 11:15 
QuestionCan this work across web applications Pinmemberjte36925-Sep-09 5:56 
Generalcustomized header links Pinmembermbruni.mka2-Sep-09 10:55 
GeneralCannot get this working on MOSS 2007 sp1 Pinmembershikarishambu7031-Jul-09 9:54 
GeneralRe: Cannot get this working on MOSS 2007 sp1 PinmemberMarian Dumitrascu31-Jul-09 10:29 
GeneralRe: Cannot get this working on MOSS 2007 sp1 Pinmemberwebwyse3-Sep-09 12:45 
GeneralRe: Cannot get this working on MOSS 2007 sp1 PinmemberDhruv198410-Dec-09 3:54 
GeneralWSS PinmemberJason L12-Jun-09 8:25 
GeneralRe: WSS PinmemberMarian Dumitrascu12-Jun-09 8:29 
GeneralRe: WSS Pinmemberjelliotboston16-Oct-09 13:11 
GeneralRe: WSS PinmemberMarian Dumitrascu16-Oct-09 14:32 

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

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

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