8. September 2008 10:17
This has become a fairly frequent request from customers using SharePoint 2007 for Web Content Management.
Specifically, in a MOSS publishing site, it is requested that links are not automatically added to navigation when the pages are created in the pages library. Instead, the page should be marked as 'hidden' in the navigation automatically when added to the pages library. This applies to either Quick Launch, or the Top Navigation (or both).
Typically this is because the governance of the site involves a different person managing the navigation than who may be managing the pages, thus even when a page is added it should not show in the nav until unhidden by another party.
The easiest way I'm aware of to achieve this is with a simple event handler on the pages libraries to hide the page once it is added.
The PublishingPage object will wrap an SPListItem for us, and give us access to the navigation settings.
Here is a simple implementation of this event receiver. Note that it references Microsoft.SharePoint.dll and Microsoft.SharePoint.Publishing.dll
public class HandlePageAdd : SPItemEventReceiver
public override void ItemAdded(SPItemEventProperties properties)
newPage = PublishingPage.GetPublishingPage(properties.ListItem);
newPage.IncludeInCurrentNavigation = false;
newPage.IncludeInGlobalNavigation = false;
// do something clever
For initial deployment and testing, I recommend you try out the fantastic Event Receiver Manager which is simple to install and will allow you to graphically add your receiver to a specific pages library without building a feature.
For proper deployment you will want to create a feature, which can install the receiver on all pages lists. You can find instructions on doing this here.