Delete Web Site Navigation Programmatically

Leave a Comment
Hello Everyone,

In a following post we will see How to delete Site Quick Launch Programmatically.
The below code snippet is a self-explanatory.
Change the URL as per your development Environment. As I have written Console Application I have hard coded the Site URL’s.

PFA Console Application for your Reference.


        /// <summary>
        /// Used to delete the Quick Launch Items of the Site
        /// </summary>
        public void NavigationDeletion()
        {
            try
            {
                using (SPSite oSite = new SPSite("SitecollectionURL"))
                {
                    using (SPWeb oWeb = oSite.OpenWeb("/SubSiteName"))
                    {
                        SPNavigationNodeCollection nodes = oWeb.Navigation.QuickLaunch;
                        for (int i = nodes.Count - 1; i > -1; i--)
                        {
                            if (!string.IsNullOrEmpty(nodes[i].Title))
                            {
                                nodes[i].Delete();                               
                            }
                            oWeb.Update();
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                //Exception Handling
            }
        }


Related Post

0 comments:

Post a Comment