top of page

Quick Launch Navigation in SharePoint 2010: Part 2

In this article we will be seeing how to add or remove the heading and links from the Quick Launch Navigation in SharePoint 2010.

Add a new custom heading to the Quick Launch Navigation

SPNavigationNode class accepts the following properties when we are creating a new heading.


a. Display Name(Required)

b. URL(Required)

c. External Link [True/False] (optional) – Specifies whether the link is internal (item in SharePoint) or external (another website)

  1. SPNavigationNodeCollection nodeColl = web.Navigation.QuickLaunch;

  2. SPNavigationNode heading1 = new SPNavigationNode("My Articles","");

  3. nodeColl.AddAsFirst(heading1);

  4. SPNavigationNode heading2 = new SPNavigationNode("My Blogs", "");

  5. nodeColl.AddAsLast(heading2);


Add a new Navigation Links to the custom heading in the Quick Launch Navigation

  1. SPNavigationNodeCollection nodeColl = web.Navigation.QuickLaunch;

  2. foreach (SPNavigationNode heading in nodeColl)                   

  3. {

  4. if (heading.Title == "My Articles")                       

  5. {

  6. SPNavigationNode link1 = new SPNavigationNode("Articles","http://www.csharpcorner.com/", true);                           

  7. heading.Children.AddAsFirst(link1);                       

  8. }

  9. if (heading.Title == "My Blogs")                       

  10. {

  11. SPList list = web.Lists.TryGetList("Blogs");

  12. SPNavigationNode link2 = web.Navigation.GetNodeByUrl(list.DefaultViewUrl);

  13. if (link2 != null)                           

  14. {                               

  15. link2 = new SPNavigationNode(list.Title, list.DefaultViewUrl);                                

  16. heading.Children.AddAsFirst(link2);                           

  17. }                       

  18. }                   

  19. }

How to delete the link 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. foreach (SPNavigationNode links in heading.Children)                       

  9. {

  10. if (links.Title == "cl1")                           

  11. {                                

  12. links.Delete();                           

  13. }                       

  14. }                                           

  15. }                                   

  16. }           

  17. }

Using PowerShell

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

  2. $web=Get-SPWeb $webURL

  3. $navigationNodeColl=$web.Navigation.QuickLaunch

  4. $heading = $navigationNodeColl | where { $_.Title -eq "Libraries" }

  5. $link = $heading.Children | where { $_.Title -eq "Shared Documents" }

  6. $link.Delete()

How to delete the heading from the Quick Launch:


Using C#

  1. SPNavigationNodeCollection nodeColl = web.Navigation.QuickLaunch;

  2. foreach (SPNavigationNode heading in nodeColl)                   

  3. {

  4. if (heading.Title == "Libraries")                       

  5. {                           

  6. heading.Delete();                       

  7. }                   


Using PowerShell

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

  2. $web=Get-SPWeb $webURL

  3. $navigationNodeColl=$web.Navigation.QuickLaunch

  4. $heading = $navigationNodeColl | where { $_.Title -eq "Libraries" }

  5. $heading.Delete()

0 comments

Comments


bottom of page