find discount viagra online

Sunday, August 31, 2014

How to update Quick Launch links programmatically in SharePoint and WSS 3.0

November 3, 2009 by · 1 Comment 

Updating quick launch navigation in SharePoint is much simpler with WSS 3.0 Microsoft.SharePoint.Navigation API. Please refer to the following sample code that will help you to iterate through all quick launch links in SharePoint sites and update them as per your liking.

private static void Traverse(string top, string from, string to)

{
 
             SPSite topSite;
             SPWebCollection subSites;
 
            try
            {
 
                topSite = new SPSite(top);
                subSites = topSite.AllWebs;
 
 
                foreach (SPWeb web in subSites)
                {
                    using (web)
                    {
                        Console.WriteLine("******** STARTING " + web.Name.ToString() + "************");
                        SPNavigationNodeCollection nodes = web.Navigation.QuickLaunch;
 
                        foreach (SPNavigationNode node in nodes)
                        {
 
                            UpdateURL(node, from, to);
 
                            SPNavigationNodeCollection childNodes = node.Children;
 
                            foreach (SPNavigationNode cNode in childNodes)
                            {
                                UpdateURL(cNode, from, to);
 
                            }
 
                        }
 
                        Console.WriteLine("******** CLOSING " + web.Name.ToString() + "************");
                    }
                }
              //  Console.ReadLine();
            }
            catch (Exception exp)
            {
                Console.WriteLine(exp.Message + " :: " + exp.StackTrace.ToString());
            }
            
 
        }
 
        private static void UpdateURL(SPNavigationNode cNode, string from, string to)
        {
            
 
            if (cNode.Url.IndexOf(from) > 0)
            {
                Console.WriteLine("FOUND CULPRIT -> " + cNode.Title.ToString() + 
             " :: " + cNode.Url.ToString());
                cNode.Url = cNode.Url.ToString().Replace(from, to);
                cNode.Update();
                Console.WriteLine(cNode.Title.ToString() + " :: " + cNode.Url.ToString());
            }
 
        }
Top Blogs

Comments

One Response to “How to update Quick Launch links programmatically in SharePoint and WSS 3.0”
  1. Sandeep Arora says:

    Hi Nauman

    I am trying to follow your approach mentioned of building Quick launch dynamically. But I am not clear on how to hook the code to a SharePoint site such that it gets executed every time through a sort of custom quick launch provider. Can you pls provide any inputs on that?

    Thanks

    Sandeep

Speak Your Mind

Tell us what you're thinking...
and oh, if you want a pic to show with your comment, go get a gravatar!

*