Click here to Skip to main content
15,867,453 members
Articles / Productivity Apps and Services / Sharepoint

Navigation Custom Control (SharePoint Server 2010)

Rate me:
Please Sign up or sign in to vote.
4.83/5 (3 votes)
15 May 2010CPOL3 min read 88.4K   1.5K   9   20
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)


Written By
Software Developer (Senior)
Canada Canada
A Microsoft Certified Professional Developer and Technology Specialist.

Experience and expertise in SharePoint 2016 / 2013 / 2010 / 2007.

Role ranges from a developer in a multi-person team to a solution consultant with expert-level skills, leading a project to completion status.

Proven experience working effectively in a team environment and a self-managed environment.

Comments and Discussions

 
QuestionNeed Clean Code: No Divs Pin
Member 860186627-Jan-12 12:02
Member 860186627-Jan-12 12:02 
GeneralLevel 2 CSS Pin
Member 814557329-Sep-11 12:19
Member 814557329-Sep-11 12:19 
GeneralRe: Level 2 CSS Pin
Member 814557329-Sep-11 12:25
Member 814557329-Sep-11 12:25 
QuestionStarting node offset? Pin
jomungand18-Nov-10 5:12
jomungand18-Nov-10 5:12 
QuestionRe: Starting node offset? Pin
Member 33236308-Aug-11 20:10
Member 33236308-Aug-11 20:10 
GeneralTrying to set StartNodeKey programmatically... Pin
woodsss23-Sep-10 2:57
woodsss23-Sep-10 2:57 
QuestionNavigation not visible Pin
S0CAR03-Sep-10 3:14
S0CAR03-Sep-10 3:14 
AnswerRe: Navigation not visible Pin
Stephen Huen3-Sep-10 10:11
Stephen Huen3-Sep-10 10:11 
GeneralRe: Navigation not visible Pin
S0CAR05-Sep-10 19:58
S0CAR05-Sep-10 19:58 
GeneralI am new to SharePoint and this Code...I am having trouble adding this code to a master page Pin
larrydunn552-Sep-10 8:59
larrydunn552-Sep-10 8:59 
I have edited the Page and added the 2dn line to the
GeneralRe: I am new to SharePoint and this Code...I am having trouble adding this code to a master page Pin
Stephen Huen3-Sep-10 10:12
Stephen Huen3-Sep-10 10:12 
QuestionThe control type 'QuestechSystems.SharePoint.Publishing.WebControls.Navigation' is not allowed on this page. The type is not registered as safe Pin
datasmithtech13-Jul-10 14:39
datasmithtech13-Jul-10 14:39 
AnswerRe: The control type 'QuestechSystems.SharePoint.Publishing.WebControls.Navigation' is not allowed on this page. The type is not registered as safe Pin
Stephen Huen14-Jul-10 16:43
Stephen Huen14-Jul-10 16:43 
QuestionThe project type is not supported by this installation Pin
Matthew Ph.9-Jul-10 3:46
Matthew Ph.9-Jul-10 3:46 
AnswerRe: The project type is not supported by this installation Pin
Stephen Huen9-Jul-10 7:50
Stephen Huen9-Jul-10 7:50 
Questionaspnetxmlsitemapprovider does not exist in the providers collection Pin
Bill - Go Steelers!24-Jun-10 7:43
Bill - Go Steelers!24-Jun-10 7:43 
AnswerRe: aspnetxmlsitemapprovider does not exist in the providers collection Pin
Stephen Huen24-Jun-10 17:42
Stephen Huen24-Jun-10 17:42 
AnswerRe: aspnetxmlsitemapprovider does not exist in the providers collection Pin
jomungand18-Nov-10 4:10
jomungand18-Nov-10 4:10 
AnswerRe: aspnetxmlsitemapprovider does not exist in the providers collection Pin
laytrix8-Nov-11 10:50
laytrix8-Nov-11 10:50 
GeneralRe: aspnetxmlsitemapprovider does not exist in the providers collection Pin
ma.... mitesh patel3-Jun-13 18:21
ma.... mitesh patel3-Jun-13 18:21 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.