Customization in SharePoint List Menus-
In SharePoint 2007, as all of us know, portal can be created within very less span of time using the OOB features... but what if the customer is skeptical about certain UI and functionality which cannot be addressed by MOSS OOB features?
The only way is to go into SharePoint customizations and it takes a lot of effort to tweak few small things.
In the subsequent blog posts I am going to write about the different customizations that we can do in SharePoint 2007 & InfoPath 2007.
So start with menubar .... what do we get as OOB?

Its a toolbar defined as a user control ascx. This control takes care of the permissions assigned to user and appropriately allows the menus which are accessible to user.
Now, we want to add some other links, menus to the toolbar for our requirement, how should we customize it?

OK - This can be done using FEATURES in SharePoint 2007.
Step 1 - Create a list definition for the particular list.
Step 2 - Create a feature in C:\Program Files\Common Files\Microsoft Shared\web server extensions\12\TEMPLATE\FEATURES withe the name you want, say "CustomMenu"
Step 3 - Then add Feature.xml file to this folder containing -
<?xml version="1.0" encoding="utf-8" ?>
<Feature Id="{255E99BB-534A-4b93-AE6A-1691C300DF7C}"
Title="Custom Menu"
Description="This example shows how you can implement custom menu."
Version="1.0.0.0"
Scope="Site"
xmlns="http://schemas.microsoft.com/sharepoint/">
<ElementManifests>
<ElementManifest Location="Element.xml" />
</ElementManifests>
</Feature>
Step 4- Now add Element.xml file in the same folder containing -
<?xml version="1.0" encoding="utf-8" ?>
<Elements xmlns="http://schemas.microsoft.com/sharepoint/">
<CustomAction Id="CustomMenu"
RegistrationType="List"
RegistrationId="3001"
GroupId="NewMenu"
Location="Microsoft.SharePoint.StandardMenu"
Sequence="1000"
ImageUrl="/_layouts/images/itann.gif"
Title="Custom Menu for sample">
<UrlAction Url=http://www.google.com/></UrlAction>
</CustomAction>
</Elements>
In this config, you need to pass Registration Id as the list template ID you created in step 1 or the ID as 100, 101 for OOB custom list, document library etc.
Step 5- Install & deploy this feature using stsadm commands.
stsadm -o deactivatefeature -filename CustomMenu\Feature.xml -url http://localhost/
stsadm -o uninstallfeature -force -filename CustomMenu\Feature.xml
stsadm -o installfeature -filename CustomMenu\Feature.xml
stsadm -o activatefeature -filename CustomMenu\Feature.xml -url http://localhost/
You need to put the URL of your site collection instead of putting http://localhost/
And here you go with the new menu in your list.
But what if you want to remove the existing menu as "New Item" as well? Is there any direct way similar to feature we used, to remove menu? The answer unfortnately is NO. And we need to try out some different technique now.

The technique is to modify the toolbar user control in Lists.
How to go for it?
Step 1 - Create new NewToolbar.ascx file
<%@ Control Language="C#" AutoEventWireup="false" %>
<mailto:%25@Assembly Name="Microsoft.SharePoint, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>
<mailto:%25@Register TagPrefix="SharePoint" Assembly="Microsoft.SharePoint, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" namespace="Microsoft.SharePoint.WebControls"%>
<mailto:%25@Register TagPrefix="Mymenu" Assembly="NewSubMenu, Version=1.0.0.0, Culture=neutral, PublicKeyToken=bb9e88afc6454ba1" namespace="Bechtel.eSub.NewSubMenu"%>
<mailto:%25@Register TagPrefix="SPHttpUtility" Assembly="Microsoft.SharePoint, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" namespace="Microsoft.SharePoint.Utilities"%>
<%@ Register TagPrefix="wssuc" TagName="ToolBar" src="~/_controltemplates/ToolBar.ascx" mce_src="~/_controltemplates/ToolBar.ascx" %>
<%@ Register TagPrefix="wssuc" TagName="ToolBarButton" src="~/_controltemplates/ToolBarButton.ascx" mce_src="~/_controltemplates/ToolBarButton.ascx" %>
<SharePoint:RenderingTemplate ID="ViewToolBar1" runat="server">
<Template>
<wssuc:ToolBar CssClass="ms-menutoolbar" EnableViewState="false" id="toolBarTbl" ButtonSeparator="<img src='/_layouts/images/blank.gif' alt=''>" RightButtonSeparator=" " runat="server">
<Template_Buttons>
<Mymenu:NewMenu ID="MyNewMenu" AccessKey="<%$Resources:wss,tb_NewMenu_AK%>" runat="server"/>
<SharePoint:ActionsMenu AccessKey="<%$Resources:wss,tb_ActionsMenu_AK%>" runat="server" />
<SharePoint:SettingsMenu AccessKey="<%$Resources:wss,tb_SettingsMenu_AK%>" runat="server" />
</Template_Buttons>
<Template_RightButtons>
<SharePoint:PagingButton ID="PagingButton1" runat="server"/>
<SharePoint:ListViewSelector ID="ListViewSelector1" runat="server"/>
</Template_RightButtons>
</wssuc:ToolBar>
</Template>
</SharePoint:RenderingTemplate>
Step 2 - Save this file in C:\Program Files\Common Files\Microsoft Shared\web server extensions\12\TEMPLATE\CONTROLTEMPLATES
Step 3- Create a receiving class to add menus to this toolbar. So create a new class library project in Visual Studio 2005. Name it as per specified in ascx (NewSubMenu).
using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.SharePoint;
using Microsoft.SharePoint.WebControls;
using System.Web.UI;
namespace NewSubMenu
{
public class NewMenu : NewMenu
{
protected override void AddMenuItems()
{
AddMenuItem("1", "New Item", "", "Click here to copy an item to this list", "/_layouts/custompage.aspx", "");
AddMenuItem("2", "New Itme 2", "", "Click here for next item ", "/_layouts/custompage.aspx", "");
}
}
}
Step 4- Compile this assembly and put it in GAC.
Step 5- Change the list defnition of the list in which you want to customize your menus. Go to schema.xml file and modify the following line to incorporate new toolbar in list-
<View BaseViewID="1" Type="HTML" WebPartZoneID="Main" DisplayName="$Resources:core,All_Tasks;" DefaultView="TRUE" MobileView="True" MobileDefaultView="False" ToolbarTemplate="ViewToolBar1" SetupPath="pages\viewpage.aspx" ImageUrl="/_layouts/images/issues.png" Url="AllItems.aspx>
Step 6- Redeploy the list definition using stsadm commands and iisreset and then here you go.
How can you change these menus for different list inherited from same list definition? -
Modify the class NewMenu we wrote to read the info from config list and populate menus depending upon the list name. So it will create the menus dynamically depending upon the list name.
In this class , this.lsit provides the SPList object of current list and you can play with it the way you want, before adding actual sub menus.
--tanuja