Click here to Skip to main content
Click here to Skip to main content
Go to top

Navigation Custom Control (SharePoint Server 2010)

, 15 May 2010
Rate this:
Please Sign up or sign in to vote.
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:

...
<%@ 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)

Share

About the Author

Stephen Huen
Software Developer (Senior)
Canada Canada
A Microsoft Certified Professional Developer and Technology Specialist.
 
Experience and expertise in SharePoint 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.
Follow on   LinkedIn

Comments and Discussions

 
QuestionNeed Clean Code: No Divs PinmemberMember 860186627-Jan-12 12:02 
GeneralLevel 2 CSS PinmemberMember 814557329-Sep-11 12:19 
GeneralRe: Level 2 CSS [modified] PinmemberMember 814557329-Sep-11 12:25 
QuestionStarting node offset? Pinmemberjomungand18-Nov-10 5:12 
QuestionRe: Starting node offset? PinmemberMember 33236308-Aug-11 20:10 
Do you have solution ?! I need to show only the sites below the main navigation (top navigation).
GeneralTrying to set StartNodeKey programmatically... Pinmemberwoodsss23-Sep-10 2:57 
QuestionNavigation not visible PinmemberS0CAR03-Sep-10 3:14 
AnswerRe: Navigation not visible PinmemberStephen Huen3-Sep-10 10:11 
GeneralRe: Navigation not visible PinmemberS0CAR05-Sep-10 19:58 
GeneralI am new to SharePoint and this Code...I am having trouble adding this code to a master page Pinmemberlarrydunn552-Sep-10 8:59 
GeneralRe: I am new to SharePoint and this Code...I am having trouble adding this code to a master page PinmemberStephen 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 Pinmemberdatasmithtech13-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 PinmemberStephen Huen14-Jul-10 16:43 
QuestionThe project type is not supported by this installation PinmemberMember 44387929-Jul-10 3:46 
AnswerRe: The project type is not supported by this installation PinmemberStephen Huen9-Jul-10 7:50 
Questionaspnetxmlsitemapprovider does not exist in the providers collection PinmemberBill - Go Steelers!24-Jun-10 7:43 
AnswerRe: aspnetxmlsitemapprovider does not exist in the providers collection PinmemberStephen Huen24-Jun-10 17:42 
AnswerRe: aspnetxmlsitemapprovider does not exist in the providers collection Pinmemberjomungand18-Nov-10 4:10 
AnswerRe: aspnetxmlsitemapprovider does not exist in the providers collection Pinmemberlaytrix8-Nov-11 10:50 
GeneralRe: aspnetxmlsitemapprovider does not exist in the providers collection Pinmemberma.... mitesh patel3-Jun-13 18:21 

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

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

| Advertise | Privacy | Mobile
Web01 | 2.8.140916.1 | Last Updated 15 May 2010
Article Copyright 2010 by Stephen Huen
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid