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
Post a Comment