Customizing Navigation Controls and Providers in SharePoint Server 2010 (ECM)

Applies to: SharePoint Server 2010

To customize navigation, you should use ASP.NET Site Navigation, because it provides a standard, consistent, and easily managed solution. For more information, see the Microsoft ASP.NET Developer Center on MSDN.

Customizing Web Display Controls (Menu, TreeView, and SiteMapPath)

You can customize the look and feel of standard display controls by using cascading style sheets (CSSs). You can also write your own ASP.NET controls and use them in navigation. To learn more, see the System.Web.UI.WebControls.Menu class documentation.


SharePoint Server 2010 also provides default navigation components that you can customize, such as the Content By Query Web Part (CQWP) and the Table of Contents Web Part. You can configure these two controls to present a custom selection of links.

The System.Web.UI.WebControls.TreeView and System.Web.UI.WebControls.Menu navigation controls bind to ASP.NET data sources, providing an abstract layer between the Web navigation controls and the underlying navigation provider.

Implementing Site Map Providers

To implement your own site map provider, you can derive a custom provider class from any of the default site map providers. SharePoint Server 2010 includes several default providers. You can also derive a custom provider class from the SiteMapProvider class in the System.Web namespace. However, deriving the SharePoint Server 2010 site map providers supplies several additional benefits, such as navigation node caching and security trimming. Therefore, you should use the SharePoint Server 2010 caching and security trimming infrastructure instead of writing your own caching and security trimming in a custom provider by deriving from the default providers.

Although the site map provider classes have approximately twenty abstract or virtual methods, only a small number must be overridden and implemented in a custom site map provider.

The following code example derives from the PortalSiteMapProvider class and demonstrates how to add items to the site map provider.

public class CustomNavProviderWithList : PortalSiteMapProvider
        public override SiteMapNodeCollection GetChildNodes(System.Web.SiteMapNode node)
            PortalSiteMapNode portalNode = node as PortalSiteMapNode;
            if (portalNode != null)
                if (portalNode.Type == NodeTypes.Area)
                    SiteMapNodeCollection nodeColl = base.GetChildNodes(portalNode);
                    using (SPSite currentSite = new SPSite(portalNode.Url))
                       SPWeb currentWeb = currentSite.OpenWeb();
                       SPListCollection lists = currentWeb.Lists;
                       foreach (SPList list in lists)
                           string listUrl = list.DefaultViewUrl;
                           PortalSiteMapNode childNode = new PortalSiteMapNode(webNode, listUrl, NodeTypes.custom, list.Title, listUrl, null);
                  return nodeColl;
                    return base.GetChildNodes(portalNode);
                return new SiteMapNodeCollection();
Public Class CustomNavProviderWithList
    Inherits PortalSiteMapProvider
        Public Overrides Function GetChildNodes(ByVal node As System.Web.SiteMapNode) As SiteMapNodeCollection
            Dim portalNode As PortalSiteMapNode = TryCast(node, PortalSiteMapNode)
            If portalNode IsNot Nothing Then
                If portalNode.Type = NodeTypes.Area Then

                    Dim nodeColl As SiteMapNodeCollection = MyBase.GetChildNodes(portalNode)
                    Using currentSite As New SPSite(portalNode.Url)
                       Dim currentWeb As SPWeb = currentSite.OpenWeb()
                       Dim lists As SPListCollection = currentWeb.Lists
                       For Each list As SPList In lists
                           Dim listUrl As String = list.DefaultViewUrl
                           Dim childNode As New PortalSiteMapNode(webNode, listUrl, NodeTypes.custom, list.Title, listUrl, Nothing)
                       Next list
                    End Using
                  Return nodeColl
                    Return MyBase.GetChildNodes(portalNode)
                End If
                Return New SiteMapNodeCollection()
            End If
        End Function
End Class

See Also





How to: Customize Navigation in SharePoint Server 2010 (ECM)

Working with Menus and Navigation Objects in SharePoint Server 2010 (ECM)