Friday, June 1, 2012

How to add Heading Sub Heading for SharePoint Navigation


SharePoint doesn't allow to add Sub Heading under Heading. Here is the code to achieve it.

SPNavigationNode oNewNode = new SPNavigationNode("Heading", "");
oWeb.Navigation.TopNavigationBar.AddAsLast(oNewNode);
oNewNode.Properties.Add("NodeType", "Heading");
oNewNode.Update();


SPNavigationNode oChild1 = new SPNavigationNode("SubHead1", "");
oNewNode.Children.AddAsFirst(oChild1);
oChild1.Properties.Add("NodeType", "Heading");
oChild1.Update();

SPNavigationNode oChild2 = new SPNavigationNode("SubHead2", "");
oNewNode.Children.Add(oChild2, oChild1);
oChild2.Properties.Add("NodeType", "Heading");
oChild2.Update();

SPNavigationNode oChild3 = new SPNavigationNode("SubHead3", "");
oNewNode.Children.Add(oChild3, oChild2);
oChild3.Properties.Add("NodeType", "Heading");
oChild3.Update();

No comments:

Post a Comment