Some time ago I have written an article about Programmatically accessing current navigation in SharePoint Publishing with the ProtalSiteMapProvider which shows how to programmatically access the current MOSS 2007 WCMS navigation. When using the PortalSiteMapProvider the way described there was no security trimming. This article describes how to set up an own sitemap provider and how to set the property SecurityTrimmingEnabled to true.
If you need to implement your own navigation and the author should be able to use the SharePoint interface to configure, sort or hide navigation nodes you can use the following approach.
Setting up your own PortalSiteMapProvider
First of all you need to edit the web.config file of your SharePoint web application and add a new provider to the node siteMap:
<add name="CustomTopNavProvider"
description="A custom SiteMapProvder with localization and security trimming"
type="Microsoft.SharePoint.Publishing.Navigation.PortalSiteMapProvider,
Microsoft.SharePoint.Publishing, Version=12.0.0.0, Culture=neutral,
PublicKeyToken=71e9bce111e9429c"
NavigationType="Global"
EncodeOutput="false"
SecurityTrimmingEnabled="True" />
With this provider you can access the top navigation because the NavigationType is set to “global”. So if you want to access the left navigation you need to set the property to “current”.
Using your own PortalSiteMapProvider
When you want to use your PortalSiteMapProvider you need to open the following namespaces:
using Microsoft.SharePoint.Publishing.Navigation;
using System.Configuration;
In order to access your own provider you can use the following code:
protected PortalSiteMapProvider map = (PortalSiteMapProvider)SiteMap.
Providers["CustomTopNavProvider"];
SiteMapNodeCollection nodeColl = map.CurrentNode.ChildNodes;
foreach (SiteMapNode childNode in nodeColl)
{
//childNode.Title;
//childNode.Key;
//childNode.Url;
}
This code allows you to respect security trimming while implementing your own navigation and reusing the SharePoint interface for configuration, sorting or hiding like the SharePoint out of the box navigation:

So that’s the end of another MOSS 2007 / WCMS development article… don’t know when the next one will appear since I have a lot of conception to-do at work.