Customize Top Navigation Programmatically in SharePoint

Requirement: Had to customize the Top navigation with bunch of provided internal/external links as part of a branding project.

Solution: Designed a feature to programmatically add links to top navigation bar. when activated, feature will add bunch of links to the top navigation bar.

Customize navigation programmatically in SharePoint:

public override void FeatureActivated(SPFeatureReceiverProperties properties)
	SPSite site = properties.Feature.Parent as SPSite;
	SPWeb rootWeb = site.RootWeb;
	// Get the top link bar.
	SPNavigationNodeCollection topNavNodes = rootWeb.Navigation.TopNavigationBar;

	// Create a simple external Link node.
	SPNavigationNode node = new SPNavigationNode("I-Best", "",true);

	//Add Heading & child Links node
	SPNavigationNode oNewNode = new SPNavigationNode("Org Browser", "");
	oNewNode.Properties.Add("NodeType", "Heading");

	SPNavigationNode oChild1 = new SPNavigationNode("Official", "");
	oChild1.Properties.Add("NodeType", "Heading");

	SPNavigationNode oChild2 = new SPNavigationNode("Leave Application","",true);
	oNewNode.Children.Add(oChild2, oChild1);

In another SharePoint 2007 Project, Had to remove all the Top navigation items and add links for custom provisioned pages. Here is the code for customizing the SharePoint top navigation bar programmatically:

//Use Unique Top navigation 
web.Navigation.UseShared = false;

//Get the top navigation to customize
SPNavigationNodeCollection topNavigationBarNodes = web.Navigation.TopNavigationBar;

//Remove All Nodes in Top navigation
for (int i = topNavigationBarNodes.Count; i > 0; i--)

//Add Top Navigation Page Links
SPNavigationNode HomePageMenuItem = new SPNavigationNode(web.Title, "Main.aspx", false);

//Add Project Documents Link
SPNavigationNode ProjectDocumentsMenuItem = new SPNavigationNode("Project Documents","ProjectDocuments.aspx", false);

//Add Project Accounting
SPNavigationNode ProjectAccountingMenuItem = new SPNavigationNode("Project Accounting", "ProjectAccounting.aspx", false);

//Add Project Checklist
SPNavigationNode ProjectChecklistMenuItem = new SPNavigationNode("Project Checklist", "ProjectChecklist.aspx", false);


Salaudeen Rajack

Salaudeen Rajack - Information Technology Expert with Two decades of hands-on experience, specializing in SharePoint, PowerShell, Microsoft 365, and related products. Passionate about sharing the deep technical knowledge and experience to help others, through the real-world articles!

One thought on “Customize Top Navigation Programmatically in SharePoint

  • Hi there Just wondering if you know a way that this could be achieved with CSOM, maybe in a console app.


Leave a Reply

Your email address will not be published. Required fields are marked *