Posted by: R Manimaran | May 31, 2011

SharePoint 2007: Delete Quick Launch nodes recursively

In SharePoint 2007, I have Navigation as shown below. I need to delete all the navigation recursively.

I here wrote a utility method which will delete all the nodes (both Heading and child Nodes).


public static void DeleteNavigation()

{

using (SPSite site = new SPSite("http://maran"))

{

using (SPWeb web = site.OpenWeb())

{

SPNavigationNodeCollection collec = web.Navigation.QuickLaunch;

for (int i = collec.Count - 1; i >0; i--)

{

int cntChildren = collec[i].Children.Count;

DeleteNavigationRecursively(collec[i]);

if (cntChildren > 0)

{

//Delete the Root Node

Console.WriteLine("Deleting Node:"+collec[i].Title);

collec[i].Delete();

}

}

}

}

}

private static void DeleteNavigationRecursively(SPNavigationNode node)

{

if (node.Children.Count == 0)

{

Console.WriteLine("Deleting Node:" + node.Title);

node.Delete();

}

else

{

for (int j = node.Children.Count - 1; j >= 0; j--)

{

DeleteNavigationRecursively(node.Children[j]);

}

}

}

Call the method DeleteNavigation will delete all the nodes recursively.

Like this at Facebook!
Advertisements

Responses

  1. Pretty! This was a really wonderful post.
    Thanks for providing this info.

  2. I have read so many articles or reviews concerning the blogger lovers except this paragraph is in fact a fastidious piece of writing, keep it up.


Leave a Reply

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

Categories

%d bloggers like this: