C# code for configuring “Navigation Editing and Sorting”

 

Here’s some code for doing what the title states. It deletes whatever is there, then adds a couple of global and current navigation nodes respectively.

string siteUrl = "https://server/sites/blank/default.aspx";
using (SPSite site = new SPSite(siteUrl))
{
    PublishingWeb pw = PublishingWeb.GetPublishingWeb(site.RootWeb);
    int count = pw.Navigation.GlobalNavigationNodes.Count;
    for (int i = 0; i < count ; i++)
    {
        pw.Navigation.GlobalNavigationNodes[0].Delete();
    }
    SPNavigationNode prev;
    prev = pw.Navigation.GlobalNavigationNodes.AddAsFirst(new SPNavigationNode("Mi Sitio", siteUrl));
    pw.Navigation.GlobalNavigationNodes.Add(new SPNavigationNode("Mi Perfil", siteUrl), prev);
    count = pw.Navigation.CurrentNavigationNodes.Count;
    for (int i = 0; i < count; i++)
    {
        pw.Navigation.CurrentNavigationNodes[0].Delete();
    }
    prev = pw.Navigation.CurrentNavigationNodes.AddAsFirst(new SPNavigationNode("Información", siteUrl));
    pw.Navigation.CurrentNavigationNodes.Add(new SPNavigationNode("Sobre Mí", siteUrl), prev);
    pw.Update();
}

This translates into this in the UI:

image