Hi All,
If we want to add top link navigation bar programmatically in our site, we can do it with programmatic support also.
First let’s have a look at from where we can do it from GUI.
Go to Site Settings-> under look and feel -> Navigation, in that point to Global Navigation and add Heading and write it down the address and other information. Once you are done with it, you can see new Tab coming up at top navigation bar and once you click on that, it will take you to the your provided address.
So the question is now how to do it programmatically. Here is the answer for that.
Here is a way. We have to get TopNavigationBar of the site first.
Let’s have a look at the demo code.
SPWeb objWeb = SPContext.Current.Web;
SPNavigationNodeCollection topNavigationNodes = objWeb.Navigation.TopNavigationBar;
This gives us the collection of all top navigation node of the site.
Now we want to add one more navigation bar to it.
SPNavigationNode objItem = new SPNavigationNode(“{Caption}”, “{URL}”, false);
And then finally add it to the Collection. Here we have a choices. Like simply add, addAsFirst, AddAsLast. Here we will add link as First.
topNavigationNodes.AddAsFirst(objItem);
objWeb.Update();
That’s it. You are done.
Now when you run the code, you can see one more link coming up at the top navigation bar and when you click there it will take you to the page mentioned by you in the URL parameter.
SharePoint Kings,Technosavvy guys hunting SharePoint Challenges... SharePoint 2013, SharePoint 2010, MOSS 2007, Windows Workflow Foundation, Project Server and Other Related Technologies.
Subscribe to:
Post Comments (Atom)
Share your SharePoint Experiences with us...
As good as the SharePointKings is, we want to make it even better. One of our most valuable sources of input for our Blog Posts comes from ever enthusiastic Visitors/Readers. We welcome every Visitor/Reader to contribute their experiences with SharePoint. It may be in the form of a code stub, snippet, any tips and trick or any crazy thing you have tried with SharePoint.
Send your Articles to sharepointkings@gmail.com with your Profile Summary. We will Post them. The idea is to act as a bridge between you Readers!!!
If anyone would like to have their advertisement posted on this blog, please send us the requirement details to sharepointkings@gmail.com
7 comments:
Where I need to place this code?
Could I place the code in Master page?
If it so for each and every page its creating the link?
I need to make it dynamically based on my list
how to achieve this?
SPWeb objWeb = SPContent.Current.Web;
should be
SPWeb objWeb = SPContext.Current.Web;
TweeZz, thanks to point typo.
Dear Thanks a lot
Ritu Ranjan
rituranjan2002@gmail.com
Dear Thanks a lot
Ritu Ranjan
it is not working.....
I could not find how to way Update links to Top Navigation Sharepoint 2010 programmatically. so today i found it, i share it to anybody at this link
http://mstechsharing.blogspot.com/2013/04/update-links-to-top-navigation.html.
Thanks
Post a Comment