I have had quite a few emails recently about ways of either hiding, showing, adding or modifying the item level menu items that appear within lists and document library. In this post I thought I would examine what you can do and what the best approach would be (in my opinion anyway). Firstly the bulk of the menu items are drawn from the “CORE.JS” file that resides in the “12” hive.
C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\12\TEMPLATE\LAYOUTS\1033
This file is a few thousand lines long so can be slightly cumbersome to work with. However the easiest way to find what you are after is to look at the name of the menu item you wish to change in UI and use this to search through the “CORE.JS”. For example I want to hide the “Send To” menu on all document libraries. To do this I would simply search the “CORE.JS” for the text “Send To”.

Notice when I do it highlights the variable called “L_Send_Text”.

Now call we have to do is search for that variable and hey presto we have found the function that is called when creating the menus.

So using this example let’s look at completely hiding the send to menu items. This is quite a simple request but has to be done in a certain way. There are really a couple of ways of doing this. They are:
1. Comment out the functions that are called within the CORE.JS
2. Use a content editor web part and add this to the relevant pages (all of them)
3. Use inline script within the Master Page
Option 1 will work well, however where possible it is not best to modify the underline files when modifying MOSS2007. Option 2 is a favourite of mine but is very hard to maintain unless you are building custom list definitions for all your content. Also it is very hard to ensure that the web part is added to every list or library. Option 3 is the best option here, simply adding the functions as inline script code will mean that any page that calls this function will automatically call the function in the Master Page, not the CORE.JS.
So let’s take option 2 for now just so we can see how this option works. The steps to take are:
1. Comment out the “AddSendSubMenu” in the CORE.JS
2. Add Content Editor Web Part to the “AllItems.aspx” page for the relevant list or library
3. Add the “AddSendSubMenu” function to the Content Editor Web Part
To comment out the function simply use the following at the beginning and the top of the function.


Now we need to add the content editor web part to the relevant pages. We will open up a document library for this and select the “Edit Page” option from the site actions menu. Once the page is edit mode press the “Add a Web Part” button.

Now we need to select the “Content Editor Web Part” to the page.

Once it is on the page press the “Open Tool Pane” link within the web part and then press the “Source Editor” button. When the dialog opens add the following code:

Once this added, if you select the item menu the “Send To” menu items will not appear.

Ok, so not everyone will want to hide functionality but the principle is the same for each menu item. I have worked on a few projects where the “DELETE” menu item has either been moved or removed from the item menu and the list or library menu bar. So let’s look at adding it back but only the email link menu item. To do this we will change the code that exists in the content editor web part to be the following:

When we now run the page the menu should then render as below:

Let’s say we wanted to have an external process run from the menu item when we click a custom link. For example we might want to send the document to another system for processing or even copy the document somewhere else. This can be done quite easy by creating a new menu item and making the link a custom “aspx” page that contains our custom code. For this example we will simply pass a few query strings to custom page. To begin with let’s modify our code slightly.

Now when we load the page it should render as below:

I won’t show the code for the other page here, as you can really do whatever you want. The URL that we constructed in the JavaScript should now look as below:
http://intranet.labs.local/StaffDirectory/_layouts/custompages/QueryStringExample.aspx?FileID=2&FileURL=http%3A%2F%2Fintranet%2Elabs%2Elocal/StaffDirectory/Team%20Documents/DemoDoc1.doc
Notice that the variables that we created have now been populated. As you can see without knowing lots of complex c# or VB.Net you can create highly customisable menus within MOSS2007.