Wednesday, August 17, 2016

Custom navigation provider in SharePoint 2013

SharePoint 2013 has many options for configuration of Global Navigation, Current Navigation and so forth. Navigation can be configured to use site hierarchy or terms store or inherit these settings. Navigation data is made available to controls in the master page via Navigation Providers. SharePoint 2013 has following OOB providers available to use as datasource.

        SPNavigationProvider
        SPSiteMapProvider
        SPContentMapProvider
        SPXmlContentMapProvider
        AdministrationQuickLaunchProvider
        SharedServicesQuickLaunchProvider
        GlobalNavSiteMapProvider
        CombinedNavSiteMapProvider
        CurrentNavSiteMapProvider
        CurrentNavSiteMapProviderNoEncode
        GlobalNavigation
        CurrentNavigation
        SiteDirectoryCategoryProvider
        MySitePersonalQuickLaunchProvider
        MySiteHostTopNavigationProvider
        GlobalNavigationSwitchableProvider
        CurrentNavigationSwitchableProvider
        GlobalNavigationTaxonomyProvider
        CurrentNavigationTaxonomyProvider
        MySiteMapProvider
        MySiteLeftNavProvider
        MySiteDocumentStaticProvider
        MySiteSitesPageStaticProvider
        MySiteSubNavProvider
        EduTopNavProvider
        MySiteHostQuickLaunchProvider

        QuickLaunchSiteMap

Despite all these options being available, at times there is a need to have a custom navigation provider which extends/modifies behavior of OOB navigation providers. I found an excellent post here which describes how such a control can be developed.

public class CustomNavProvider : SiteMapProvider
{
    private const string PROVIDERNAME = "GlobalNavigationTaxonomyProvider";

    public override SiteMapNode RootNode
    {
        get
        {
            return SiteMap.Providers[PROVIDERNAME].RootNode;
        }
    }

    public override SiteMapNode CurrentNode
    {
        get
        {
            return SiteMap.Providers[PROVIDERNAME].CurrentNode;
        }
    }

    public override SiteMapNodeCollection GetChildNodes(SiteMapNode parent)
    {
        SiteMapNodeCollection childNodes = new SiteMapNodeCollection();
        if ((parent == null) || (parent.Key == null)) return childNodes;

        foreach (SiteMapNode tempNode in SiteMap.Providers[PROVIDERNAME].GetChildNodes(parent))
        {
            //do stuff with tempNode
            childNodes.Add(tempNode);
        }

        return childNodes;
    }

    public override SiteMapNode FindSiteMapNode(string rawUrl)
    {
        return SiteMap.Providers[PROVIDERNAME].FindSiteMapNode(rawUrl);
    }

    public override SiteMapNode GetParentNode(SiteMapNode node)
    {
        return SiteMap.Providers[PROVIDERNAME].GetParentNode(node);
    }
}    

No comments:

c# httpclient The remote certificate is invalid according to the validation procedure: RemoteCertificateNameMismatch

 If we get this error while trying to get http reponse using HttpClient object, it could mean that certificate validation fails for the remo...