In this article we will be seeing about top link bar inheritance in SharePoint
using object model.
I have a site collection and three subsites (Subsite1, Subsite2 and Subsite3).
In the Subsite3 I am going to inherit the navigation links from the parent site
top link bar.
Top Link Bar Inheritance:
The sub site can inherit the navigation links from the parent site top link bar.
When you create a site through user interface (Go to Site Actions => More
Options => Site => Select the template), in the right hand side you could see an
option "More options".
![InheShare1.gif]()
In that you could see Navigation Inheritance section, by default no is selected.
If you choose yes the navigation links from the parent site top link bar will be
inherited.
![InheShare2.gif]()
Programmatically inherit top link bar:
- Open Visual Studio 2010.
- Go to File => New => Project.
- Select Console Application from the
installed templates.
- Enter the name and click on ok.
- Replace Program.cs with the following
code.
using
System;
using
System.Collections.Generic;
using
System.Linq;
using
System.Text;
using
Microsoft.SharePoint;
using
System.Xml;
using
Microsoft.SharePoint.Navigation;
namespace
TopLinkBarInheritance
{
class Program
{
static void
Main(string[] args)
{
using (SPSite
siteCollection = new
SPSite("http://servername:1111/sites/sample"))
{
using (SPWeb
web = siteCollection.OpenWeb("Subsite3"))
{
web.Navigation.UseShared=true;
}
}
}
}
}