Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- SPSecurity.RunWithElevatedPrivileges(delegate()
- {
- using (SPSite oSiteCollection = new SPSite("http://mySiteUrl"))
- {
- using (SPWeb oWeb = oSiteCollection.OpenWeb())
- {
- oWeb.AllowUnsafeUpdates = true;
- // Create the node.
- SPNavigationNodeCollection _quickLaunchNav = oWeb.Navigation.QuickLaunch;
- SPNavigationNode _SPNode = new SPNavigationNode("Link Title", "http://link_url", true); //i tried with false, too. It didn't work
- _quickLaunchNav.AddAsLast(_SPNode);
- oWeb.Update(); //added this since I've seen it in some examples, but not every example had it
- }
- }
- });
- public override void FeatureActivated(SPFeatureReceiverProperties properties)
- {
- using (SPSite site = (SPSite)properties.Feature.Parent)
- {
- using (SPWeb web = site.RootWeb) {
- {
- // Add links to navigation
- SPNavigationNode listNode = new SPNavigationNode("Visitors", "Lists/Visitors/All Visitors.aspx");
- SPNavigationNode newVisitorNode = new SPNavigationNode("Register New Visitor", "Lists/Visitors/NewForm.aspx");
- SPNavigationNode siteContentsNode = new SPNavigationNode("Site Contents", "_layouts/15/viewlsts.aspx");
- web.Navigation.QuickLaunch.AddAsLast(listNode);
- web.Navigation.QuickLaunch.AddAsLast(newVisitorNode);
- web.Navigation.QuickLaunch.AddAsLast(siteContentsNode);
- web.Update();
- }
- }
- }
- // references
- using Microsoft.SharePoint.Publishing;
- using Microsoft.SharePoint.Navigation;
- using Microsoft.SharePoint.Publishing.Navigation;
- // code to add Navigation link
- using (SPSite spSite = SPContext.Current.Site)
- {
- using (SPWeb web = spSite.OpenWeb())
- {
- string headingTitle = "myPageTitle";
- string headingUrl = "http://mysitename.com/SitePage/myPage.aspx";
- // Get the Quick Launch headings.
- SPNavigationNodeCollection ql = web.Navigation.QuickLaunch;
- // If a Resources heading exists, get it.
- SPNavigationNode heading = ql.Cast<SPNavigationNode>().FirstOrDefault(n => n.Title == headingTitle);
- // If the Resources heading does not exist, create it.
- if (heading == null)
- {
- heading = new SPNavigationNode(headingTitle, headingUrl);
- heading = ql.AddAsLast(heading);
- }
- }
- }
- SPSite spSite = (SPSite)properties.Feature.Parent
- using (SPWeb web = spSite.OpenWeb())
- {
- SPNavigationNode listNode = new SPNavigationNode("Visitors", "Lists/Visitors/All Visitors.aspx");
- SPNavigationNode newVisitorNode = new SPNavigationNode("Register New Visitor", "Lists/Visitors/NewForm.aspx");
- SPNavigationNode siteContentsNode = new SPNavigationNode("Site Contents", "_layouts/15/viewlsts.aspx");
- SPNavigationNodeCollection nodes = web.Navigation.QuickLaunch;
- nodes.AddAsLast(listNode);
- nodes.AddAsLast(newVisitorNode);
- nodes.AddAsLast(siteContentsNode);
- web.Update();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement