Sunday, January 26, 2014

Custom Sitemap provider in SharePoint does not show n-level :@

Another genius SharePoint  limitation or issue , If you want to implement your own custom site map provider, To implement your own Sitemap provider on SharePoint you will have to inherit from the following class :
  • -          Microsoft.SharePoint.Publishing.Navigation. PortalSiteMapProvider
  • -          Then you will have to override the following method
    • public override SiteMapNodeCollection GetChildNodes(SiteMapNode node)
  • -          After implementing your custom logic with a static or recursive algorithm (In my case was a recursive algorithm to get all navigation terms from Managed Metadata Service in a specific term set), You will find that only 2 levels are showing in the top navigation menu ….weiiiiird
  • -          Ok google it… you will find that this maybe an issue in the <SharePoint:Aspmenu> control in your masterpage which contains a property called MaximumDynamicDisplayLevels,,, OOOOH this maybe my life saver…. :@ but no SharePoint will not make your life that easy.
  • -          Playing around with this property and other properties like StaticDisplayLevels but in vain .
  • -          So what is happening in the background … Time to reflect some code
  • -          Reflecting the  Microsoft.SharePoint.Publishing.Navigation. PortalSiteMapProvider class … Here you will have following  surprise



-          Yes you are seeing it right, Microsoft engineers for some UNKNOWN reason had decided to HARDCODE the MaximumSupportedNodeDepth as a PROTECTED property to be UNACCESSABLE .
-          Now implement your logic but this time inherit for the classic System.Web.StaticSiteMapProvider implement the following methods:
o   public override SiteMapNode BuildSiteMap()
o   protected override SiteMapNode GetRootNodeCore()
-          You now have your own customized top navigation site map provider supporting n-level hierarchy


-          Happy SharePointing :)

No comments:

Post a Comment