How to add an item to the quick launch in SharePoint

Here is a method to add a node to the quick launch.  You need to pass in the name you want displayed for the link, the Site,  and the path to the page you want the link to open.
This method checks if the link already exists and it won’t add the node if it does.  So it’s safe to run multiple time without jacking up your quick launch.

private void AddNodeToQuickLaunch(string linkName, string SiteToOpen, string pathtoPage)
       {
           try
           {
               using (SPWeb web = SPContext.Current.Site.OpenWeb(SiteToOpen))
               {
                   web.AllowUnsafeUpdates = true;

                   SPNavigationNodeCollection nodes = web.Navigation.QuickLaunch;

                   SPNavigationNode createNode = new SPNavigationNode(linkName, pathtoPage, true);

                   foreach (SPNavigationNode node in nodes)
                   {
                       bool nodeExists = false;
                       if (node.Title.Equals("Lists"))
                       {
                           foreach (SPNavigationNode child in node.Children)
                           {
                               if (child.Title == linkName)
                               {
                                   nodeExists = true;
                               }
                           }

                           if (!nodeExists)
                           {
                               node.Children.Add(createNode, node);
                           }
                       }
                   }
                   web.AllowUnsafeUpdates = false;
               }
           }
           catch (Exception ex)
           {
               throw ex;
           }
       }
[tweetmeme only_single=”false”]
Advertisements

4 thoughts on “How to add an item to the quick launch in SharePoint

  1. Hello superb blog! Does running a blog similar to this require a
    large amount of work? I’ve very little knowledge of computer programming but I had been hoping to start my own blog in the near future. Anyhow, should you have any recommendations or tips for new blog owners please share. I know this is off subject however I simply needed to ask. Appreciate it!

    • Doing a blog does take time, but you can do it whenever you want.
      Blogging on WordPress.com is very easy.

      I try following different professional bloggers on twitter. They have different tips.
      @jeffbullas has a lot of good info.

Got something to add?

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s