Sometimes, when applying branding to Sharepoint sites, it’s necessary to hide the quicklaunch bar.
Some people do that by overriding the css styles, and basically making it invisible. This is a good approach for when, on certain pages, we need to display the quicklaunch, while on the others we need to hide it.
Please note that the quicklaunch it’s always there, with this approach. It’s simply not visible.
For a situation where we’ll never want to display the quicklaunch, we can simply deactivate it, with a feature.
Let’s say we create a feature called “HideQuickLaunch”, scoped for a site (Web). On the event receiver we can override the following methods:
//disable quicklaunch on feature activation
public override void FeatureActivated(SPFeatureReceiverProperties properties)
{
using (SPWeb currentWeb = (SPWeb)properties.Feature.Parent)
{
currentWeb.AllowUnsafeUpdates = true;
currentWeb.QuickLaunchEnabled = false;
currentWeb.Update();
currentWeb.AllowUnsafeUpdates = false;
}
}
//enable quicklaunch on feature deactivation
public override void FeatureDeactivating(SPFeatureReceiverProperties properties)
{
using (SPWeb currentWeb = (SPWeb)properties.Feature.Parent)
{
currentWeb.AllowUnsafeUpdates = true;
currentWeb.QuickLaunchEnabled = false;
currentWeb.Update();
currentWeb.AllowUnsafeUpdates = false;
}
}
Be First to Comment