Here is a method to add a node to the quick launch. You need to pass in the name you want displayed for the link, the Site, and the path to the page you want the link to open.
This method checks if the link already exists and it won’t add the node if it does. So it’s safe to run multiple time without jacking up your quick launch.
private void AddNodeToQuickLaunch(string linkName, string SiteToOpen, string pathtoPage) { try { using (SPWeb web = SPContext.Current.Site.OpenWeb(SiteToOpen)) { web.AllowUnsafeUpdates = true; SPNavigationNodeCollection nodes = web.Navigation.QuickLaunch; SPNavigationNode createNode = new SPNavigationNode(linkName, pathtoPage, true); foreach (SPNavigationNode node in nodes) { bool nodeExists = false; if (node.Title.Equals("Lists")) { foreach (SPNavigationNode child in node.Children) { if (child.Title == linkName) { nodeExists = true; } } if (!nodeExists) { node.Children.Add(createNode, node); } } } web.AllowUnsafeUpdates = false; } } catch (Exception ex) { throw ex; } }
Advertisements
Hello superb blog! Does running a blog similar to this require a
large amount of work? I’ve very little knowledge of computer programming but I had been hoping to start my own blog in the near future. Anyhow, should you have any recommendations or tips for new blog owners please share. I know this is off subject however I simply needed to ask. Appreciate it!
Doing a blog does take time, but you can do it whenever you want.
Blogging on WordPress.com is very easy.
I try following different professional bloggers on twitter. They have different tips.
@jeffbullas has a lot of good info.
Is there an issue if one adds 4 level navigation into the Quick Launch programatically?
No it just becomes a messy interface.