In this article we will be seeing how to manage the Quick Launch Navigation in SharePoint 2010 using PowerShell and SharePoint Object Model. Get all the Headings and Links from the Quick Launch: Using C#: using (SPSite site = new SPSite("http://serverName:1111/sites/SPSiteDataQuery/")) { using (SPWeb web = site.RootWeb) { SPNavigationNodeCollection nodeColl = web.Navigation.QuickLaunch; foreach (SPNavigationNode heading in nodeColl) { Console.WriteLine(heading.Title.ToString());
foreach (SPNavigationNode links in heading.Children) { Console.WriteLine("-" + links.Title.ToString()); } } Console.ReadLine(); } } Output: Using PowerShell: $siteURL="http://serverName:1111/sites/SPSiteDataQuery/" $site=Get-SPSite $siteURL $web=$site.RootWeb $navigationNodeColl=$web.Navigation.QuickLaunch foreach($heading in $navigationNodeColl) { write-host -f Green $heading.Title foreach($links in $heading.Children) { write-host -f Yellow $links.Title } } Output: Move the Headings in the Quick Launch: In this we will be seeing how to move the headings in the Quick Launch Navigation. Initially Quick Luanch Navigation looks like the following. MoveToLast and MoveToFirst Methods: using (SPSite site = new SPSite("http://serverName:1111/sites/SPSiteDataQuery/")) { using (SPWeb web = site.RootWeb) { SPNavigationNodeCollection nodeColl = web.Navigation.QuickLaunch; foreach (SPNavigationNode heading in nodeColl) { if (heading.Title.ToString() == "Libraries") { heading.MoveToLast(nodeColl); } if (heading.Title.ToString() == "Lists")| { heading.MoveToFirst(nodeColl); } } } } Move Method: using (SPSite site = new SPSite("http://serverName:1111/sites/SPSiteDataQuery/")) { using (SPWeb web = site.RootWeb) { SPNavigationNodeCollection nodeColl = web.Navigation.QuickLaunch; SPNavigationNode heading = nodeColl[0]; heading.Move(nodeColl, nodeColl[1]); } }
You need to be a premium member to use this feature. To access it, you'll have to upgrade your membership.
Become a sharper developer and jumpstart your career.
$0
$
. 00
monthly
For Basic members:
$20
For Premium members:
$45
For Elite members: