in SharePoint 2007

Highlighting the current page (site) in a custom navigation

When you build your custom navigation menu in SharePoint, highlighting the current page in the navigation menu is one of the various things we like to do. Something like this:

image

You can see how People and Skills Development funding is highlighted and also their parent items – ANZBPF programmes and Australia and New Zealand Biotechnology Partnership Fund

I hope you are using PortalSiteMapProvider to build your custom navigation. Below is a code snippet which gets all the pages in a particular site

PortalSiteMapProvider psmp = PortalSiteMapProvider.CurrentNavSiteMapProvider;

psmp.IncludePages = PortalSiteMapProvider.IncludeOption.Always;

    

SiteMapNode siteMapNode = psmp.FindSiteMapNode(elevatedWeb.ServerRelativeUrl);

List<SiteMapNode> nodes=new List<SiteMapNode>();

 

foreach(SiteMapNode node in siteMapNode.ChildNodes)

{

    nodes.Add(node);

}

 

// now bind the List to repeater or ListView etc.,

Given a SiteMapNode, here is a method which can find whether that particular node is current page

private bool IsCurrentPage(SiteMapNode node)

{

    return node.Url.ToLowerInvariant() == 

             HttpContext.Current.Request.Url.LocalPath.ToLowerInvariant();

}

Now you can easily change the CSS styling for the selected node in your navigation based on whether it is current page or not.

 

 

You can also manipulate the URL and find out whether it is your current site too

Write a Comment

Comment

Time limit is exhausted. Please reload the CAPTCHA.