SiteName = "your site name here";
using (SPSite site = new SPSite(SiteName))
SPWeb quickLaunchWeb = site.OpenWeb();
SPNavigationNodeCollection quickLaunchNodes =
//deletes the first and second child underneath the 7th heading on
//Notice that deleting any children is easy as long as you know the
position...You can probably also check the children's names too
and create a dynamic component and loop through the quick
launch list and delete items by adding an if or for loop.
//creates 5 children underneath the 7th heading
SPNavigationNodeCollection quickLaunchNodes2 =
SPNavigationNode externalSubMenuItem1 =
new SPNavigationNode("Link1", "Url1", true);
SPNavigationNode externalSubMenuItem2 =
new SPNavigationNode("Link2", "Url2", true);
SPNavigationNode externalSubMenuItem3 =
new SPNavigationNode("Link3", "Url3", true);
quickLaunchWeb.Navigation.UseShared = true;
//You only need one update statement for all the remove and adds,
on first shot I accidentally added it twice and learned this lesson.
I came up with this program really quick and it was a console application. I added the first part of the site and had a console.readline statement to type in the site number, because ours were numerically based. I wanted to double check every site to see if anything was broken in other areas. If you want a quicker version, then you could probably just run any site in that specific web or read from an outside data source. For example, we have a web service that lists all the sites I could have called the web service to get the number and add/remove items from the quick launch with one go at the program. If you guys would like a script example on how to use these items that I added to the quick launch to change the links with one file let me know. I have a script that dynamically replaces specific text through the master file. I hope that you guys enjoy.
Re-Posted from Old Blog