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:
- 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.
- All webs implementing this navigator must have the Office SharePoint Server Publishing feature activated.
And, there are three major steps for installation:
- Add the DLL to the GAC
- Add the navigation provider to the web.config
- 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:
Culture=neutral, PublicKeyToken=fc448b9e121af773" />
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.
- Be sure you keep a backup copy of the master page you are going to change.
- Be sure you are doing 1.
- Open the master page in your HTML editor of choice.
- Locate this control:
<SharePoint:DelegateControl runat="server" ControlId="TopNavigationDataSource">, and underneath it, place this control:
- Locate this control:
<SharePoint:AspMenu ID="TopNavigationMenu" ….. You should find it above the control we modified in 4.
Change the attributes
StaticDisplayLevels to 1:
- If you use the out-of-the-box default.master page, all these changes should look like this:
<StaticMenuItemStyle CssClass="ms-topnav" ItemSpacing="0px"/>
<StaticSelectedStyle CssClass="ms-topnavselected" />
<StaticHoverStyle CssClass="ms-topNavHover" />
- When you upload the modified master page, don’t forget there are three important steps to follow:
- Check in
- Publish as a Major Version
- Approve the new master page
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.
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.
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.
- May 29th, 2009 - Published.
Seek, create and combine solutions in the realm of Information Portals, Business Inteligence and Business Automation. With a focus on SharePoint. (Houston, TX)