![]() |
Enterprise Systems »
SharePoint Server »
General
Intermediate
License: The Code Project Open License (CPOL)
Shared Navigation for SharePoint Site CollectionsBy Marian DumitrascuA SharePoint navigation provider for sharing top navigation with any site collection inside the same farm. |
XML, C#3.0, Windows, .NET, ASP.NET, Dev
|
|
Advanced Search Add to IE Search |
|
|
|
||||||||||||||||
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:
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.
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:
And, there are three major steps for installation:
<!-- ... -->
<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>
<!-- ... -->
SourceSite parameter to be the URL of the source site collection from where you want to borrow the navigation.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.
<SharePoint:DelegateControl runat="server" ControlId="TopNavigationDataSource">, and underneath it, place this control:<asp:SiteMapDataSource ShowStartingNode="False" SiteMapProvider="SharedNavigationProvider" id="topSiteMap2" runat="server"/>
<SharePoint:AspMenu ID="TopNavigationMenu" ….. You should find it above the control we modified in 4.Change the attributes DataSourceID to topSiteMap2 and StaticDisplayLevels to 1:
DataSourceID="topSiteMap2" StaticDisplayLevels="1"
<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"/>
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.The code, of course, can be improved:
| You must Sign In to use this message board. | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
General
News
Question
Answer
Joke
Rant
Admin
Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads.
|
PermaLink |
Privacy |
Terms of Use
Last Updated: 29 May 2009 Editor: Smitha Vijayan |
Copyright 2009 by Marian Dumitrascu Everything else Copyright © CodeProject, 1999-2010 Web17 | Advertise on the Code Project |