How to hide pages from the navigation programmatically
If you have ever had a play around with the navigation settings in SharePoint you will see that you can tell it to automatically show sites and show pages. The pages option works great if you have a small number of pages in your site that you want in the nav, but what if you don’t want to see all of the pages? Well in the UI you can select the individual page and choose “Hide” on the navigation settings page, nice an easy – but doing this through code is a bit more annoying.
Basically you need to add the GUID for the page to a property of the SPWeb object to get it to hide, something like this:
SPWeb web; // get this however you need to for the context you are in SPListItem item = web.Lists["Pages"].Items[0]; // again get the list item object however you need to web.AllProperties["__CurrentNavigationExcludes"] += item.UniqueId.ToString(); + ";" web.Update();
Basically that ‘__CurrentNavigationExcludes’ option controls what items should be hidden in the nav as a semi-colon delimited list, so you can put in the GUID of a page (or even a site) to have it hidden from the current (quick launch) navigation. If you use the ‘__GlobalNavigationExcludes’ option you can hide items from the top navigation as well.
It is also worth mentioning that when you update the properties of the web you should use the AllProperties property instead of the Properties one. If you use SPWeb.Properties when you add you change it will always go in as lower case, and these settings are case sensitive. SPWeb.AllProperties does not have this issue so you should be sure to stick with it.




Dear Brian,
I have a big problem based on the navigation in MOSS. I have to create products and categories pages.
My first thought was create site collections per category. But there are too much category and I also have a lot of site collections.
The products created as pages (with field controls) in a Pages library (and the categories with CQWP). But I have to implement 3 category level. So the deepest would be Category1->Category1.1->Category1.1.1
And of course I need urls like the category hiearchy:
http://example.org/category1/category11/category111/fooproduct.aspx
Do you think that can be solved by using URL rewriting and some kinda navigation “hack” within one Page Library? I don’t have too much useful tips.
I hope you can help me some way
regards,
gjozsi
I’ll be honest, I’m not sure how easy this would be to do with MOSS. If I were you I would definately be looking at the URL rewriting stuff as a first port fo call. Combine that with some good use of metadata to implement your categories and you should be able to pull it off.
Thanks! I look forward to solve it. If I finish I’ll post it as a comment if I don’t cause bother. :-)