Download Source :
Custom Navigation Sharepoint 2010
using System;
using System.Runtime.InteropServices;
using System.Security.Permissions;
using Microsoft.SharePoint;
using Microsoft.SharePoint.Navigation;
namespace
SharePoint2010.CustomNavigation.Features.CustomNavigationFeature
{
/// <summary>
/// This class handles events raised during feature
activation, deactivation, installation, uninstallation, and upgrade.
/// </summary>
/// <remarks>
/// The GUID attached to this class may be used during
packaging and should not be modified.
/// </remarks>
[Guid("87c29feb-c8e8-4a1f-8a8d-2cae3122c241")]
public class CustomNavigationFeatureEventReceiver : SPFeatureReceiver
{
//
Uncomment the method below to handle the event raised after a feature has been
activated.
public override void
FeatureActivated(SPFeatureReceiverProperties properties)
{
SPWeb currentWeb =
(SPWeb)properties.Feature.Parent;
#region addding the departments node
SPNavigationNode DepartmentsNode = new SPNavigationNode("Departments", "#", true);
DepartmentsNode =
currentWeb.Navigation.TopNavigationBar.AddAsLast(DepartmentsNode);
DepartmentsNode.Properties.Add("NodeType", "Heading");
DepartmentsNode.Update();
//adding
Administration
SPNavigationNode AdministrationNode
= new
SPNavigationNode("Administration", "/Pages/default.aspx", true);
DepartmentsNode.Children.AddAsFirst(AdministrationNode);
AdministrationNode.Update();
//adding
Maintenance
SPNavigationNode MaintenanceNode = new SPNavigationNode("Maintenance", "/Pages/default.aspx", true);
DepartmentsNode.Children.AddAsFirst(MaintenanceNode);
MaintenanceNode.Update();
//adding
Operations
SPNavigationNode OperationsNode = new SPNavigationNode("Operations", "/Pages/default.aspx", true);
DepartmentsNode.Children.AddAsLast(OperationsNode);
OperationsNode.Update();
//adding
Technical and Process Engineering
SPNavigationNode TechPENode = new SPNavigationNode("Technical and Process Engineering", "/Pages/default.aspx", true);
DepartmentsNode.Children.AddAsLast(TechPENode);
TechPENode.Update();
//adding
BPF
SPNavigationNode BPFNode = new SPNavigationNode("Business Planning and Finance", "/Pages/default.aspx", true);
DepartmentsNode.Children.AddAsLast(BPFNode);
BPFNode.Update();
//adding
Maintenance
SPNavigationNode SupplyChainNode = new SPNavigationNode("Supply Chain", "/Pages/default.aspx", true);
DepartmentsNode.Children.AddAsLast(SupplyChainNode);
SupplyChainNode.Update();
//adding
Operations
SPNavigationNode ISDNode = new SPNavigationNode("IsS", "Pages/default.aspx", true);
DepartmentsNode.Children.AddAsLast(ISDNode);
ISDNode.Update();
//adding
Technical and Process Engineering
SPNavigationNode ITNode = new SPNavigationNode("IT", "Pages/default.aspx", true);
DepartmentsNode.Children.AddAsLast(ITNode);
ITNode.Update();
//adding
BPF
SPNavigationNode NIPRASNode = new SPNavigationNode("NsdsIPRAS", "Pages/default.aspx", true);
DepartmentsNode.Children.AddAsLast(NIPRASNode);
NIPRASNode.Update();
#endregion
}
//
Uncomment the method below to handle the event raised before a feature is
deactivated.
public override void FeatureDeactivating(SPFeatureReceiverProperties
properties)
{
//delete
the top navigation when deactivate..
SPWeb currentWeb =
(SPWeb)properties.Feature.Parent;
SPNavigationNodeCollection nodes =
currentWeb.Navigation.TopNavigationBar;
for (int i = nodes.Count - 1; i >= 0; i--)
{
nodes[i].Delete();
}
currentWeb.Update();
currentWeb.AllowUnsafeUpdates = false;
}
//
Uncomment the method below to handle the event raised after a feature has been
installed.
//public
override void FeatureInstalled(SPFeatureReceiverProperties properties)
//{
//}
//
Uncomment the method below to handle the event raised before a feature is
uninstalled.
//public
override void FeatureUninstalling(SPFeatureReceiverProperties properties)
//{
//}
//
Uncomment the method below to handle the event raised when a feature is
upgrading.
//public
override void FeatureUpgrading(SPFeatureReceiverProperties properties, string
upgradeActionName, System.Collections.Generic.IDictionary<string, string>
parameters)
//{
//}
}
}