This is one of the things in MOSS 2007 / WCMS development which are not obvious but can save some time if you know it.  Some time ago i blogged about the PortalSiteMapProvider and how you can use it to build your custom navigation:

These things work really fine but if you want to have external links in your navigation you need to be aware that the object behind a navigation node can be different.

image

Here you can see 3 different types in the SharePoint UI:

image

The first 2 nodes are of type site, the next 2 are pages and the last is my external link. External link means that if you click it the link should be opened in a new tab (target=’_blank’).

PortalSiteMapProvider and SPNavigationSiteMapNode

You get a PortalSiteMapProvider object like I have described it in the older posts:

PortalSiteMapProvider map = new PortalSiteMapProvider();
SiteMapNodeCollection nodeColl = map.CurrentNode.ChildNodes;
	
foreach (SiteMapNode childNode in nodeColl)
{     
    //childNode.Title;    
    //childNode.Key;     
    //childNode.Url;
}

If you iterate through the childNodes you have an object of type [Microsoft.SharePoint.Publishing.Navigation.PortalWebSiteMapNode] which has no property where it says that this link is external or not. The external link has an object of type [Microsoft.SharePoint.Publishing.Navigation.SPNavigationSiteMapNode] which has a property called isExternal (boolean). You need to cast the childNode:

if (childNode.GetType() == typeof(Microsoft.SharePoint.Publishing.Navigation.
SPNavigationSiteMapNode)) { bool externalLink = ((Microsoft.SharePoint.Publishing.Navigation.
SPNavigationSiteMapNode)(childNode)).IsExternal; }

Works great ;)

Add comment





  Country flag
 

biuquote
Loading