Click here to Skip to main content
65,938 articles
CodeProject is changing. Read more.
Articles / productivity / SharePoint

Navigation Custom Control (SharePoint Server 2010)

4.83/5 (3 votes)
15 May 2010CPOL3 min read 90.7K   1.5K  
Renders navigational nodes in HTML list tags

Introduction

For use in Microsoft SharePoint Server 2010, this web control is an alternative to the out-of-the-box "Current Navigation" a.k.a. AspMenu. It renders navigational nodes using HTML list tags, like:

This web control is adapted from my SharePoint Server 2007 version for use in SharePoint Server 2010.

Description

The web control uses PortalSiteMapProvider to render navigation nodes. Although the SharePoint 2010 version of AspMenu supports emission of HTML list tags with the use of property UseSimpleRendering, it is still fairly rigid in how children levels are displayed when you are at the top level and when you navigate down the nodes.

It has several public properties:

  • SiteMapProvider - A site map provider of type PortalSiteMapProvider. Default is CurrentNavigation.
  • StartNodeKey - Server relative URL for a starting sub-site. For example: /PressReleases/2010. Default is the root site.
  • IncludeSubSites - Include sub-sites? Allowed values are True, False, or PerWeb. Default is PerWeb, i.e., a per sub-site setting, configurable in Site Actions > Navigation (Look and Feel).
  • IncludePages - Include pages? Allowed values are True, False, or PerWeb. Default is PerWeb, i.e., a per sub-site setting, configurable in Site Actions > Navigation (Look and Feel)
  • IncludeHeadings - Include headings? Allowed values are True, False.
  • IncludeAuthoredLinks - Include authored links? Allowed values are True, False.
  • MaxLevels - Maximum number of node levels. Default is 0, i.e., no limit.
  • CompactMode - If set to True, the navigation expands the top level nodes and all parent nodes to the current node. In the example below, nodes Child1, Child2, and Child3 are the top level nodes:
    Child1
    Child2
        Child21
            Child211 (Current Node)
                Child2111
    Child3
    

    If set to False, sibling nodes to the current node and its parent nodes will also be shown. For example:

    Child1
    Child2
        Child21
            Child211 (Current Node)
                Child2111
            Child212
        Child22
        Child23
    Child3
    

    Default is False.

  • ListCssClass - CSS class name for the outermost <ul> tag.
  • NodeCssClass - CSS class name for regular hyperlinked nodes.
  • CurrentNodeCssClass - CSS class name for a selected node.
  • CurrentNodeParentCssClass - CSS class name for the lowest level node under which there is a selected node.
  • NoUrlNodeCssClass - CSS class name for nodes with no URL, like headings.

The control also uses a resource file to store all messages and property attribute UI strings. It demonstrates how to develop a custom class that inherits CategoryAttribute or DescriptionAttribute and returns a localized string from your own Resource Manager.

The sample Visual Studio 2010 solution includes all the support files you need to build and deploy this web control, minus the strong name key file (key.snk). It makes full use of the built-in SharePoint integration. No more third party tools or custom pre and post build scripts are needed to build the SharePoint solution file.

Notes

The web control does not fully support site hierarchy containing navigational "headings" because they cannot be clicked to open up child nodes. The navigation will, however, show parent headings if one of the child nodes is a current node.

Installation

Open SharePoint 2010 Management Shell, add solution file QuestechNavigation.wsp using Add-SPSolution like:

Add-SPSolution "C:\QuestechSystems.Navigation\bin\Release\QuestechNavigation.wsp"

Or using stsadm, add solution file QuestechNavigation.wsp like:

stsadm -o addsolution -filename 
	"C:\QuestechSystems.Navigation\bin\Release\QuestechNavigation.wsp"

Go to SharePoint 2010 Central Administration/System Settings/Manage farm solutions. Deploy the installed solution to selected web applications. To insert the web control to a publishing page, modify the appropriate master page or page layout as follows:

ASP.NET
...
<%@ Register Tagprefix="QuestechPublishingWebControls"
    Namespace="QuestechSystems.SharePoint.Publishing.WebControls"
    Assembly="QuestechSystems.SharePoint.Publishing.Navigation, Version=1.0.0.0, 
              Culture=neutral, PublicKeyToken=57d955ce9c425b79" %>
...
...
<QuestechPublishingWebControls:Navigation CompactMode="False" runat="server" />
...

History

  • 15th May, 2010: Initial post

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)