Showing posts with label Heading. Show all posts
Showing posts with label Heading. Show all posts

Monday, June 11, 2012

Add SPNavigation Heading programmatically

If you want to add header without link to SharePoint Navigation pro-grammatically,  Need to set some values in the NavigationNode.Properties HashTable.


            SPNavigationNode node, node1;
            // Get the parent’s top link bar.
            SPNavigationNodeCollection topnav = web.Navigation.TopNavigationBar;

            // Create the node.
            node = new SPNavigationNode("News", "/news", true);
            topnav.AddAsLast(node);

            node = new SPNavigationNode("Services", string.Empty, true);
            node = topnav.AddAsLast(node);
            node.MakeHeaderNode();
            node1 = new SPNavigationNode("IT Support", "/Services/Lists/Helpdesk Initiation/NewForm.aspx?RootFolder=&source=/", true);
            node.Children.AddAsLast(node1);


public static class SPNavigationNodeExtensions
{
    public static void MakeHeaderNode(this SPNavigationNode node)
    {
        node.Properties["BlankUrl"] = "True";
        node.Properties["LastModifiedDate"] = DateTime.Now;
        node.Properties["Target"] = "";
        node.Properties["vti_navsequencechild"] = "true";
        node.Properties["UrlQueryString"] = "";
        node.Properties["CreatedDate"] = DateTime.Now;
        node.Properties["Description"] = "";
        node.Properties["UrlFragment"] = "";
        node.Properties["NodeType"] = "Heading";
        node.Properties["Audience"] = "";
        node.Update();
    }
}
As you can see, the “BlankUrl'” = True, and NodeType = “Heading”.