Add links -
SPSite site = SPContext.Current.Site;
SPWeb myWeb = site.RootWeb;
SPSecurity.RunWithElevatedPrivileges(delegate()
{
using (SPSite siteCollection = new SPSite(site.ID))
{
using (SPWeb web = siteCollection.OpenWeb(myWeb.ID))
{
web.AllowUnsafeUpdates = true;
SPNavigationNodeCollection nodes = web.Navigation.QuickLaunch;
SPNavigationNode navNode = new SPNavigationNode(“My Lib Link”, “/Pages/lib/Allitems.aspx”, false);
nodes.AddAsFirst(navNode);
}
}
}
Delete Links - This example is for deleting all the links in quick launch
SPSecurity.RunWithElevatedPrivileges(delegate()
{
using (SPSite siteCollection = new SPSite(site.ID))
{
using (SPWeb web = siteCollection.OpenWeb(myWeb.ID))
{
web.AllowUnsafeUpdates = true;
for (int i = web.Navigation.QuickLaunch.Count-1; i > -1; i–)
{
web.Navigation.QuickLaunch[i].Delete(); -> Deleting all the links in quick launch
}
}
}
}
Ads by Google
No comments:
Post a Comment