Monday, August 03, 2009

Add\remove Quick launch link

       Add a quick launch link group

     public static void AddQuickLaunchGroup(SPWeb web, string groupName)
        {
            SPNavigationNodeCollection quickLaunchNodes = web.Navigation.QuickLaunch;
            SPNavigationNode groupMenu = new SPNavigationNode(groupName, "", false);
            quickLaunchNodes.AddAsFirst(groupMenu);
            web.Update();
        }

        Remove quick link group-

        public static void RemoveQuickLaunchGroup(SPWeb web, string groupName)
        {
            SPNavigationNodeCollection quickLaunchNodes = web.Navigation.QuickLaunch;
            foreach (SPNavigationNode node in quickLaunchNodes)
            {
                if (string.Compare(node.Title, groupName) == 0)
                {
                    quickLaunchNodes.Delete(node);
                    web.Update();
                    break;
                }
            }
        }

        Add Quick launch link to a group-


        public static void AddQuickLaunchLink(SPWeb web, string groupName, string linkName, string linkUrl)
        {
            SPNavigationNodeCollection quickLaunchNodes = web.Navigation.QuickLaunch;
            foreach (SPNavigationNode node in quickLaunchNodes)
            {
                if (string.Compare(node.Title, groupName) == 0)
                {
                    SPNavigationNode linkNode = new SPNavigationNode(linkName, linkUrl, true);
                    node.Children.AddAsFirst(linkNode);
                    web.Update();
                    break;
                }
            }
        }

        Remove quick launch link from a group-


        public static void RemoveQuickLaunchLink(SPWeb web, string groupName, string linkName)
        {
            SPNavigationNodeCollection quickLaunchNodes = web.Navigation.QuickLaunch;
            foreach (SPNavigationNode node in quickLaunchNodes)
            {
                if (string.Compare(node.Title, groupName) == 0)
                {
                    foreach (SPNavigationNode nodeChild in quickLaunchNodes)
                    {
                        if (string.Compare(nodeChild.Title, linkName) == 0)
                        {
                            node.Children.Delete(nodeChild);
                            web.Update();
                            break;
                        }
                    }
                }
            }
        }

1 comments:

vikas mehta said...

the code for delete does not works :(