Export (0) Print
Expand All

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

Last modified: April 04, 2010

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.

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.

Note Note

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.

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);
                           nodeColl.Add(childNode);
                    }
                  }
                  return nodeColl;
                }
                else
                {
                    return base.GetChildNodes(portalNode);
                }
            }
            else
            {
                return new SiteMapNodeCollection();
            }
        }
    }

Community Additions

ADD
Show:
© 2014 Microsoft