Cross web application navigation SharePoint 2010- Part I
In real life Sharepoint applications it is common practice to have
consistent global navigation (or top navigation bar) across site. It is
achievable out of the box with Sharepoint navigation architecture. But
it is also common situation when site collection (SPSite) contains
multiple sites (SPWeb) and there is a requirement to have consistent
navigation when users goes through sites within site collection (it can
be navigation items from one of the particular sites, e.g. site
collection root site, or it can be navigation items retrieved from
custom storage like xml file, database, etc). More complicated case – is
when navigation should be preserved within multiple site collections.
This
is problem scope which I would like to address in the several posts
including this one. I will go from simple to complex and start from most
simple scenario: when we have single site collection and several sites
under it. First case will assume that we are limited by WSS only. It
means neither site collection root web nor its subsites are publishing
sites. Publishing sites (sites with publishing infrastructure) have
their own navigation API (see previous post)
– and it is much more complicated task to preserve cross-publishing
sites navigation. I will describe it in next part of navigation-related
posts.
- SPNavigationProvider - provides a base class for Windows SharePoint Services site-map providers that are specialized for SharePoint site navigation;
- SPSiteMapProvider - provides the SiteMapNode objects that constitute the global content breadcrumb, which represents objects in the site hierarchy above the current site;
- SPContentMapProvider - provides methods and properties for implementing a site map provider for contents of a Windows SharePoint Services site. This class provides the SiteMapNode objects that constitute the content breadcrumb, where “content” referes to the lists, folders, items, and list forms composing the breadcrumb;
- SPXmlContentMapProvider - provides methods and properties for implementing a site map provider for contents of a Windows SharePoint Services site. This class provides the SiteMapNode objects that constitute the content breadcrumb, where “content” referes to the lists, folders, items, and list forms composing the breadcrumb.
SPNavigationProvider will help us if need to keep navigation from one particular site. If we will look the code of SPNavigationProvider using reflector we will found that it has public virtual Web property which returns current SPWeb instance:
public class SPNavigationProvider : SiteMapProvider
{
...
protected virtual SPWeb Web
{
get
{
return SPControl.GetContextWeb(HttpContext.Current);
}
}
}
public class SingleWebNavigationProvider : SPNavigationProvider
{
...
protected override SPWeb Web
{
get
{
return SPContext.Current.Site.RootWeb;
}
}
}
<siteMap defaultProvider="SPNavigationProvider" enabled="true">
<providers>
...
<add name="SingleWebNavigationProvider"
type="NamespaceName.SingleWebNavigationProvider, AssemblyName" />
</providers>
</siteMap>
<asp:SiteMapDataSource
ShowStartingNode="False"
SiteMapProvider="SingleWebNavigationProvider"
id="topSiteMap"
runat="server"/>
Second case – preserving navigation globally can be achieved by using SPXmlContentMapProvider. Specify web application-relative path in its siteMapFile property in web.config:
<siteMap defaultProvider="SPNavigationProvider" enabled="true">
<providers>
...
<add name="SPXmlContentMapProvider" siteMapFile="_app_bin/layouts.sitemap"
type="Microsoft.SharePoint.Navigation.SPXmlContentMapProvider, Microsoft.SharePoint,
Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" />
</providers>
</siteMap>
<asp:SiteMapDataSource
ShowStartingNode="true"
SiteMapProvider="SPXmlContentMapProvider"
id="topSiteMap"
runat="server"/>
This is all what I wanted to tell about in part 1. In next part II will show how to preserve cross-site and cross-site collection navigation for publishing sites.
No comments:
Post a Comment