top of page

Top Link bar inheritance in SharePoint 2010

Writer: Vijai Anand RamalingamVijai Anand Ramalingam

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".


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.


Programmatically inherit top link bar:

a. Open Visual Studio 2010.

b. Go to File => New => Project.

c. Select Console Application from the installed templates.

d. Enter the name and click on ok.

e. Replace Program.cs with the following code.

  1. using System;

  2. using System.Collections.Generic;

  3. using System.Linq;

  4. using System.Text;

  5. using Microsoft.SharePoint;

  6. using System.Xml;

  7. using Microsoft.SharePoint.Navigation;

  8. namespace TopLinkBarInheritance

  9. {

  10. class Program   

  11. {

  12. static void Main(string[] args)       

  13. {

  14. using (SPSite siteCollection = new SPSite("http://servername:1111/sites/sample"))           

  15. {

  16. using (SPWeb web = siteCollection.OpenWeb("Subsite3"))               

  17. {                  

  18. web.Navigation.UseShared=true;               

  19. }           

  20. }       

  21. }   

  22. }

  23. }


f. Hit F5.

g. Go to the Subsite3, the top link bar looks like the following






erver'>

Comments


bottom of page