Quick Launch Navigation in SharePoint 2010: Part1

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#:

  1. using (SPSite site = new SPSite("http://serverName:1111/sites/SPSiteDataQuery/"))           

  2. {

  3. using (SPWeb web = site.RootWeb)               

  4. {

  5. SPNavigationNodeCollection nodeColl = web.Navigation.QuickLaunch;

  6. foreach (SPNavigationNode heading in nodeColl)                   

  7. {

  8. Console.WriteLine(heading.Title.ToString());

  9. foreach (SPNavigationNode links in heading.Children)                        

  10. {

  11. Console.WriteLine("-" + links.Title.ToString());                       

  12. }                                           

  13. }

  14. Console.ReadLine();               

  15. }           

  16. }

Output:















Using PowerShell:

  1. $siteURL="http://serverName:1111/sites/SPSiteDataQuery/"

  2. $site=Get-SPSite $siteURL

  3. $web=$site.RootWeb

  4. $navigationNodeColl=$web.Navigation.QuickLaunch

  5. foreach($heading in $navigationNodeColl)

  6. {

  7. write-host -f Green $heading.Title

  8. foreach($links in $heading.Children)

  9. {

  10. write-host -f Yellow $links.Title

  11. }

  12. }

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 Launch Navigation looks like the following.


















MoveToLast and MoveToFirst Methods:

  1. using (SPSite site = new SPSite("http://serverName:1111/sites/SPSiteDataQuery/"))           

  2. {

  3. using (SPWeb web = site.RootWeb)               

  4. {

  5. SPNavigationNodeCollection nodeColl = web.Navigation.QuickLaunch;

  6. foreach (SPNavigationNode heading in nodeColl)                   

  7. {

  8. if (heading.Title.ToString() == "Libraries")                       

  9. {                           

  10. heading.MoveToLast(nodeColl);                       

  11. }

  12. if (heading.Title.ToString() == "Lists")|                       

  13. {                           

  14. heading.MoveToFirst(nodeColl);                       

  15. }                                     

  16. }                                  

  17. }           

  18. }

















Move Method:

  1. using (SPSite site = new SPSite("http://serverName:1111/sites/SPSiteDataQuery/"))           

  2. {

  3. using (SPWeb web = site.RootWeb)               

  4. {

  5. SPNavigationNodeCollection nodeColl = web.Navigation.QuickLaunch;

  6. SPNavigationNode heading = nodeColl[0];                   

  7. heading.Move(nodeColl, nodeColl[1]);               

  8. }           

  9. }