Adding links to quick launch navigation of SharePoint team site

Here is the scenario: you`re working on a SharePoint intranet based of SharePoint team site template; your client asks you to add extra links to SharePoint quick launch navigation menu that will point users to external locations and some views on libraries within your portal. You need to add those links as part of your solution package. How do you do that?

One of the ways you can achieve that is by using a feature with an event receiver and execute adding code that will take care of adding those links to already created site either as a part of the deployment or once the site has been deployed.

Here is how my feature.xml will look like:

<?xml version=”1.0″ encoding=”utf-8″?>
<Feature xmlns=”http://schemas.microsoft.com/sharepoint/”
Id=”E8931816-9652-4f17-86F1-2A8772418C96″
Title=”Add Quick Launch Links”
Description=”Add Quick Launch Links”
Version=”1.0.0.0″
Scope=”Web”
Hidden=”False”
ImageUrl=”"
ReceiverAssembly=”Ahs.Cts.SharePoint, Version=1.0.0.0, Culture=neutral, PublicKeyToken=xxxxxxxxxxxxxxxxx”
ReceiverClass=”MyAccount.AddQuickLaunchLinks”>
<ElementManifests>
</ElementManifests>
</Feature>

<?xml version=”1.0″ encoding=”utf-8″?>

<Feature xmlns=”http://schemas.microsoft.com/sharepoint/”

Id=”E8931816-9652-4f17-86F1-2A8772418C96″

Title=”Add Quick Launch Links”

Description=”Add Quick Launch Links”

Version=”1.0.0.0″

Scope=”Web”

Hidden=”False”

ImageUrl=”"

ReceiverAssembly=”Ahs.Cts.SharePoint, Version=1.0.0.0, Culture=neutral, PublicKeyToken=xxxxxxxxxxxxxxxxx”

ReceiverClass=”MyAccount.AddQuickLaunchLinks”>

<ElementManifests>

</ElementManifests>

</Feature>

My event receiver will sit in its own file called AddQuickLinks and look like this:
class AddQuickLaunchLinks : SPFeatureReceiver
{
#region Events
public override void FeatureActivated(SPFeatureReceiverProperties properties)
{
using (SPWeb rootweb = properties.Feature.Parent as SPWeb)
{
SPNavigationNodeCollection nodes = rootweb.Navigation.QuickLaunch;
SPNavigationNode navNode = new SPNavigationNode(“My List”, “~/Page1.aspx”, true);
nodes.AddAsFirst(navNode);
}
}
……………………………
As you may have guessed I get a hold of the SPNavigationNodeCollection and add new node with my url and name.
This entry was posted in MOSS, sharepoint and tagged , , , . Bookmark the permalink.

Comments are closed.