Inherit / Stop Web Site Top-Level Navigation

We have two option on Top Link bar navigation, either we can inherit the Top-Link bar from the parent site or use the own Top-Level navigation.

Sharing the Top-link bar can be achieved through browser interface by navigating,

1) Site Actions –> Site Settings

2) On Site Settings page, under Look and Feel section, click Top link bar

3) On Top Link bar page, Click Use Links from Parent and then Click OK in pop-up box to share the Top-Links between Sites.

or

3) On Top Link bar page, Click Stop Inheriting Links to stop the Shared links between sites and used to have the own Top-Links for the site.

The following section contains the code to achieve the Share and Stop the inheriting links

Code allows to Share the Top-Level links between all the sub-sites under Top Level Site

using (SPSite site = new SPSite(“http://localhost”))
{
    SPWeb web = site.RootWeb;
    //We can’t able to Set true to top level site or root site
    foreach (SPWeb subweb in web.Webs)
    {
        //Check if the subsite  not Sharing the Top-Links
        if (!subweb.Navigation.UseShared)
        {
            subweb.Navigation.UseShared = true;
        }
        subweb.Dispose();
    }
    web.Dispose();
}

Code allows to Stop the Top-Level links between all the sub-sites under Top Level Site

using (SPSite site = new SPSite(“http://localhost”))
{
    SPWeb web = site.RootWeb;
    foreach (SPWeb subweb in web.Webs)
    {
        //Check if the subsite already Shared the Top-Links
        if (subweb.Navigation.UseShared)
        {
            subweb.Navigation.UseShared = false;
        }
        subweb.Dispose();
    }
    web.Dispose();
}

 

We don’t need to call SPWeb.Update() to update the Link Sharing.

Shantha Kumar
Shantha Kumar
Articles: 280

24,849 Comments

    • Hi Douglas,

      This is not a java script code and I have used Server Side OM code to achieve that functionality. You can run this code in Console application, or you can create a web part also to achieve the same result.

Comments are closed.