3

If a publishing site collection has managed or structural navigation set as the source for the top navigation, how do you work with these settings programmatically? The SPWeb.Navigation.TopNavigationBar property returns an entirely different set of navigation nodes (the Top Link Bar on non-publishing sites).

Here are some UI screenshots where the settings I'm talking about are located:

Not-Publishing (Top Link Bar Settings):

Top Link Bar Settings

Publishing (Global Navigation Settings):

Publishing Navigation Settings Global Navigation Settings

How can you programmatically detect whether a site is using the SPNavigation.TopNavigationBar, Managed Navigation, or Structural Navigation for its Global Navigation / top navigation settings?

1
  • Reverse compiling the Microsoft.SharePoint.Publish.dll now... will add an answer if I can get this working. Otherwise, maybe someone else already has a solution? Commented Jan 23, 2014 at 20:16

1 Answer 1

3

Alright, so after peering into the inner workings of the code behind for those settings pages, I've found that you can detect the source of the publishing site's navigation by using the WebNavigationSettings class and reading its GlobalNavigation.Source property (a StandardNavigationSource enum) like such:

if (PublishingWeb.IsPublishingWeb(web))
{
    WebNavigationSettings settings = new WebNavigationSettings(web);
    switch (settings.GlobalNavigation.Source)
    {
        case StandardNavigationSource.PortalProvider:
            // Data source is Structured Navigation
            break;
        case StandardNavigationSource.TaxonomyProvider:
            // Data source is Managed Navigation
            break;
        case StandardNavigationSource.InheritFromParentWeb:
            // Root navigation data source is inherited
            break;
        case StandardNavigationSource.Unknown:
            // The documentation for this value states:
            // "Returns a value of unknown to indicate an advanced configuration
            // that does not correspond to one of the standard configurations.
            // This value cannot be manually assigned to the Source property."
            break;
    }
}
else
{
    // Non-publishing site, root source is SPNavigation.TopNavigationBar
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.