Friday, December 10, 2010

Add/Delete/Update Quicklaunch Navigation Programmatically in Sharepoint

SPSite site = new SPSite("sitename"); SPWeb Web = site.OpenWeb(); SPNavigationNodeCollection nodes = Web.Navigation.QuickLaunch; SPNavigationNode NavNodeWorkingDoc = null; SPNavigationNode NavNodePicLib = null; SPNavigationNode NavNodeRefLib = null; SPNavigationNode navNodeFinalDoc = null; SPNavigationNode navNodePublished = null; SPNavigationNode navNodeDisclosed = null; foreach (SPNavigationNode node in nodes) { if (node.Title.Equals("Documents")) //Documents { foreach (SPNavigationNode childnode in node.Children) { if (childnode.Title.Equals("Documents")) { childnode.Delete(); //childnode.Url = "url name" } else if (childnode.Title.Equals("Project Documents")) { NavNodeWorkingDoc = childnode; NavNodeWorkingDoc.Title = "Working Documents"; NavNodeWorkingDoc.Update(); } else if (childnode.Title.Equals("Picture Library")) { NavNodePicLib = childnode; NavNodePicLib.Title = "Picture Gallery"; NavNodePicLib.Update(); } else if (childnode.Title.Equals("Reference Library")) { NavNodeRefLib = childnode; } } node.Children.Add(navNodeFinalDoc, NavNodeRefLib); node.Children.Add(navNodePublished, navNodeFinalDoc); node.Children.Add(navNodeDisclosed, navNodePublished); } }

No comments:

Post a Comment

Followers