re-ordering navigation for quick launch section (SharePoint2010)



using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.SharePoint;
using Microsoft.SharePoint.Administration;
using Microsoft.SharePoint.Navigation;

namespace ConsoleOperations
{
    class MovingNavigationLinks
    {
        static void Main(string[] args)
        {
            using (SPSite site = new SPSite("http://localhost:5030"))
            {
                site.AllowUnsafeUpdates = true;

                using (SPWeb web = site.RootWeb)
                {
                    int moveToHeadingIndex = 0;
                    var nodesToMove = new List<SPNavigationNode>();
                    int index = 0;
                    foreach (SPNavigationNode heading in web.Navigation.QuickLaunch)
                    {
                        if (heading.Title == "nameOfNavigationHead")
                        {
                            moveToHeadingIndex = index;
                        }
                        else
                        {
                            foreach (SPNavigationNode child in heading.Children)
                            {
                                if (child.Title == "nameofChildNode1" ||
                                    child.Title == "nameofChildNode2")|| etc
                                {
                                    nodesToMove.Add(child);
                                }
                            }
                        }
                        index++;
                    }
                    SPNavigationNodeCollection headingNodeCollection = web.Navigation.QuickLaunch[moveToHeadingIndex].Children;
                    foreach (SPNavigationNode node in nodesToMove)
                    {
                        node.MoveToLast(headingNodeCollection);
                    }
                }
            }
        }
    }
}

Comments

Popular posts from this blog

javascript to get the all site user in sharepoint 2010 (Getting all Site users using Client Object Model)

Adding Navigation Links To Quick Launch Bar Programatically (SharePoint 2010)

Disable all day event, Recurrence,Workspace Fields in Calendar list