News

Events
About Me:
I am a 26 year old female SharePoint Enthusiast. I work for B&R Business Solutions from my home in Olathe, KS. I have been working with SharePoint since I attended the Portal University in 2005. I hold a BA in Computer Science from the University of Missouri - Kansas City. I love playing Rockband, organizing user group meetings, working with MOSS, attending Code Camps as a speaker, and having bizarre conversations about geek things with cool people. If you have any comments or questions fill out the contact form and I will try my best to help.

Rebecca Isserman's Facebook profile

My Stats

  • Posts - 200
  • Comments - 248
  • Trackbacks - 0

Twitter












Tag Cloud


Recent Comments


Recent Posts


Archives


Post Categories


B&R Blogs


Kansas City Community Blogs


Other Blogs


SharePoint Blogs



I ran into a problem last week, where I need to update multiple sites navigation really quick by deleting and adding items to the navigation on the quick launch bar.  I found this great entry from Todd Baginski: http://www.sharepointblogs.com/tbaginski/archive/2007/12/26/how-to-programmatically-customize-site-navigation-in-wss-3-0-and-moss-2007.aspx.  I wanted to take this a step further by removing nodes from underneath a specific heading.  Then I wanted to re-add different nodes, so that I could pull up some javascript that would change the links based on certain phrases (i.e. http://reports, http://sql/[Specific Annual Report]).  Here is the sample code for the quick launch additions and removals:

                SiteName = "your site name here";

                    using (SPSite site = new SPSite(SiteName))
                    {


                        SPWeb quickLaunchWeb = site.OpenWeb();

                        SPNavigationNodeCollection quickLaunchNodes =  
                        quickLaunchWeb.Navigation.QuickLaunch;
                       
                       //deletes the first and second child underneath the 7th heading on
                       the page
                        quickLaunchNodes[6].Children.Delete(quickLaunchNodes[6].
                        Children[0]);
                        quickLaunchNodes[6].Children.Delete(quickLaunchNodes[6].
                        Children[1]);

                        //Notice that deleting any children is easy as long as you know the
                           position...You can probably also check the children's names too 
                          and create a dynamic component and loop through the quick 
                          launch list and delete items by adding an if or for loop.


                        //creates 5 children underneath the 7th heading
                        SPNavigationNodeCollection quickLaunchNodes2 = 
                                           quickLaunchWeb.Navigation.QuickLaunch;


                        SPNavigationNode externalSubMenuItem1 = 
                                        new SPNavigationNode("Link1", "Url1", true);

                        quickLaunchNodes2[6].Children.AddAsLast(externalSubMenuItem1);

                        SPNavigationNode externalSubMenuItem2 =
                                  new SPNavigationNode("Link2", "Url2", true);

                        quickLaunchNodes2[6].Children.AddAsLast(externalSubMenuItem2);

                        SPNavigationNode externalSubMenuItem3 =
                                    new SPNavigationNode("Link3", "Url3", true);

                       quickLaunchNodes2[6].Children.AddAsLast(externalSubMenuItem3);



                        quickLaunchWeb.Navigation.UseShared = true;

                         //You only need one update statement for all the remove and adds,
                             on first shot I accidentally added it twice and learned this lesson.
                         quickLaunchWeb.Update();
                    }

I came up with this program really quick and it was a console application.  I added the first part of the site and had a console.readline statement to type in the site number, because ours were numerically based.  I wanted to double check every site to see if anything was broken in other areas.  If you want a quicker version, then you could probably just run any site in that specific web or read from an outside data source.  For example,  we have a web service that lists all the sites I could have called the web service to get the number and add/remove items from the quick launch with one go at the program.  If you guys would like a script example on how to use these items that I added to the quick launch to change the links with one file let me know.  I have a script that dynamically replaces specific text through the master file.  I hope that you guys enjoy.

Re-Posted from Old Blog


posted @ Wednesday, February 27, 2008 6:26 PM |

Comments

Gravatar # re: Programmatically Add and Remove Items from the Quick Launch Bar
Posted by vipasane on 4/16/2008 6:14 AM
This solution will show those nodes which are excluded in naivgation. How to exclude those?

Gravatar # re: Programmatically Add and Remove Items from the Quick Launch Bar
Posted by MOSSLover on 4/16/2008 3:21 PM
Here is a little code example:
SPWeb Web = SPContext.Current.Web;
SPList List = Web.Lists["Your List Name"];

//needs to be here so you can update the web
Web.AllowUnsafeUpdates = true;

//adds list to quick launch
List.OnQuickLaunch = true;

//must call to update list or library
List.Update();

This is some rough code you probably want some exception handling and such.
Gravatar # re: Programmatically Add and Remove Items from the Quick Launch Bar
Posted by vipasane on 4/18/2008 2:20 AM
I have a site and I've checked that it shouldn't be shown in navigation. And if I use code above to make quick launch that site will be included in nodes.
Is there some property which says wheater if this site has been excluded in navigation or how to manage?
Is the only option to make a separate list which has all excluded nodes and iterate it through while making quick launch?

Gravatar # re: Programmatically Add and Remove Items from the Quick Launch Bar
Posted by MOSSLover on 4/18/2008 7:48 AM
I found this code off a post:
web.Navigation.QuickLaunch[i].IsVisible = false; web.Update();

What you can probably do is look at the header or url in the navigation node and then hide that node.
Gravatar # re: Programmatically Add and Remove Items from the Quick Launch Bar
Posted by Dragon on 5/13/2008 8:02 AM
This is good stuff. Thanks! I can definitely use this. Now I have a question for you. How can one programmatically make the Quick Launch minimize and expand either horizontally or vertically, similarly to minimizing a web part?. I know how to hide it programatically with a little css in the Content Editor Web Part and this blog is good for quick add/remove changes to the contents but minimizing it like a true web part is what I'm looking for. Can you help?
Gravatar # re: Programmatically Add and Remove Items from the Quick Launch Bar
Posted by MOSSLover on 5/14/2008 10:43 PM
I will have some answers for you in the upcoming weeks, because we are going to implement something similar. In the meantime someone told me you could probably do it in javascript. You probably could get rid of the default control and write a web user control or web part that would implement a menu looping through all the quick launch nodes. I promise when I figure this out that I will post a solution.
Gravatar # re: Programmatically Add and Remove Items from the Quick Launch Bar
Posted by bhargavi on 5/20/2008 8:27 AM
Hi,.. thanks for your posting, but i have a different situation, i need to hide some items in the quick launch based on user permissions.Is it possible to hide?
Gravatar # re: Programmatically Add and Remove Items from the Quick Launch Bar
Posted by Becky Isserman on 5/21/2008 7:38 AM
If you setup SharePoint Groups and add the AD Groups or users to the quick launch that you want to give the right to see that item. Then I believe there is a place in the object model to set the audiences for that item.
Gravatar # re: Programmatically Add and Remove Items from the Quick Launch Bar
Posted by bhargavi on 5/22/2008 9:29 AM
ok thanks.. i will try my luck with audiences, but is there a way to hide the items in the quick launch, i tried using "isVisible" property but that didnot work for me.
Gravatar # re: Programmatically Add and Remove Items from the Quick Launch Bar
Posted by MOSSLover on 5/22/2008 5:11 PM
What exactly are you trying to hide? If you want to hide something from everyone and it's a list or library, then you can do it in the list or library. If it's a page or site, then you can use the .visible functionality. If you want it hidden from certain users, then the audiences are good for you. It all depends on the situation.
Gravatar # re: Programmatically Add and Remove Items from the Quick Launch Bar
Posted by Bhargavi on 5/26/2008 12:28 AM
ok let me explain -
i want to hide the links - discussions,sites , surveys and lists from the quick launch. The approach i used was to get all the nodes of the quick launch, and get the node corresponding to the above mentioned links and said - node.isVisible=false. This did not work for me.
Gravatar # re: Programmatically Add and Remove Items from the Quick Launch Bar
Posted by Sreeni on 6/10/2008 3:42 PM
Bhargavi,
You can make it as quicklaunch=false in Onet.xml. That might work for you
Gravatar # re: Programmatically Add and Remove Items from the Quick Launch Bar
Posted by bountykiller on 6/17/2008 9:34 AM
Same Problem Here. I wanted to create my own menu, taking node from the current navigation, but the "IsVisible" property is true for each nodes, even the hidded ones. Anyone has a solution?
Gravatar # re: Programmatically Add and Remove Items from the Quick Launch Bar
Posted by bountykiller on 6/17/2008 10:15 AM
Same Problem Here. I wanted to create my own menu, taking node from the current navigation, but the "IsVisible" property is true for each nodes, even the hidded ones. Anyone has a solution ?
Gravatar # re: Programmatically Add and Remove Items from the Quick Launch Bar
Posted by MOSSLover on 6/26/2008 8:25 PM
What you could do is build a custom control or web part and delete the default control. Using a AspMenu Control in the SharePoint Object Model. You could then hide the control in the ondatabound using css or create some type of security where the control does not show up in the page load event.
Gravatar # re: Programmatically Add and Remove Items from the Quick Launch Bar
Posted by Qassem on 9/29/2008 9:55 AM
I need your help here http://social.msdn.microsoft.com/Forums/en-US/sharepointcustomization/thread/695a323a-03f3-43ac-9ad4-ee931f27f11b
Gravatar # re: Programmatically Add and Remove Items from the Quick Launch Bar
Posted by Avinash on 12/1/2008 10:04 PM
It's wonderful work!
Gravatar # re: Programmatically Add and Remove Items from the Quick Launch Bar
Posted by Rob on 3/18/2009 5:55 AM
Hi,
Thanks for your code. It helped me with the solution of my problem. In my situation I ran into a problem with adding (internal) links under, e.g., the sites heading. On my blog I add a post about this, because it's slightly different.
Gravatar # re: Programmatically Add and Remove Items from the Quick Launch Bar
Posted by Tanmay Bari on 3/19/2009 9:15 AM
Same Problem Here. I wanted to create my own menu, taking node from the current navigation, but the "IsVisible" property is true for each nodes, even the hidded ones. Anyone has a solution ?
Gravatar # re: Programmatically Add and Remove Items from the Quick Launch Bar
Posted by Marco on 7/9/2009 10:53 AM
someone know how get information about quicklaunch using sharepoint's Webservices??
maybe using Sites.asmx or SiteData.asmx.
I need only get this information.
Thanks.
Post A Comment
Title:
Name:
Email:
Website:
Comment:
Verification: