What's on the Menu? - How to Remove Items from a Document Library Drop-down Menu

 

The SDK includes documentation explaining how to create a custom Jscript file that can override the default functions that create items in the cute little drop-down menu associated with list items.  For example, the drop-down below is for a PowerPoint presentation in a WSS document library:

 

The SDK describes how to override a default method (AddCheckinCheckoutMenuItem) in order to create a new Check Out & Save item on the menu.

 

Customizing the Shortcut Menu for List Items

 

However, what if we want to *remove* items from the menu?  For example, let's say that we want to remove the "Edit in Microsoft Office…" link from the menu so that our users are not presented with that option;  how would we go about it?  How would we override default methods in order to remove any of the other items on the menu (Alert Me, Discuss, etc.)?

 

To begin, we have to look at the function in ows.js that creates the document library menu items:  AddDocLibMenuItems.  Within this function, you'll see a bunch of calls to the CAMOpt function, which is also defined in ows.js.  CAMOpt is the function responsible for actually writing each menu item;  if we remove the call to CAMOpt for a specific menu item, we effectively remove that menu item!

 

For example, the AddDoclibMenuItems function contains the following code, which writes the "Edit in [Application]" menu item:

 

setDocType();

if (currentItemAppName != "" && currentItemOpenControl != "")

{

strDisplayText = StBuildParam(L_EditIn_Text, currentItemAppName);

strAction = "editDocumentWithProgID2('" + currentItemFileUrl + "', '" + currentItemProgId + "', '" + currentItemOpenControl + "')";

strImagePath = ctx.imagesPath + currentItemIcon;

CAMOpt(m, strDisplayText, strAction, strImagePath);

}

 

If we comment out the call to CAMOpt…

 

//CAMOpt(m, strDisplayText, strAction, strImagePath);

 

...the "Edit in [Application]" item/option will no longer show up for menus on document library items.  Below is a screenshot of the menu for a PowerPoint presentation on a WSS site where a custom ows.js file has been applied (following the instructions in Customizing the Shortcut Menu for List Items) that *only* includes an overridden AddDoclibMenuItems function with the specific CAMOpt call above commented out:

 

 

 

So, how can you figure out which CAMOpt call is adding which menu item?  Simple.  :)  The second parameter passed is the display text (strDisplayText);  all of the calls to CAMOpt in AddDocLibMenuItems use a string constant for this parameter.  The string constants are defined in ows.js, and I've reprinted them below:

 

=====

var L_Edit_Text= "Edit";

var L_ViewItem_Text= "View Item";

var L_EditItem_Text= "Edit Item";

var L_EditSeriesItem_Text = "Edit Series";

var L_DeleteItem_Text= "Delete Item";

var L_DeleteDocItem_Text  = "Delete";

var L_ViewProperties_Text = "View Properties";

var L_EditProperties_Text = "Edit Properties";

var L_Discuss_Text= "Discuss";

var L_Subscribe_Text= "Alert Me";

var L_Review_Text= "Send for Review";

var L_EditIn_Text= "Edit in ^1";

var L_Checkin_Text= "Check In";

var L_Checkout_Text= "Check Out";

var L_CreateDWS_Text= "Create Document Workspace";

var L_PublishBack_Text= "Publish to Source Location";

var L_Versions_Text= "Version History";

var L_Reply_Text= "Reply";

var L_ExportContact_Text  = "Export Contact";

var L_ExportEvent_Text= "Export Event";

var L_Reschedule_Text= "Rescheduling Options";

var L_Move_Text= "Move";

var L_Keep_Text= "Keep";

var L_Delete_Text= "Delete";

var L_Open_Text= "Open";

var L_SiteSettings_Text   = "Change Site Settings";

var L_ManageUsers_Text= "Manage Users";

var L_DeleteSite_Text= "Delete Site";

var L_SiteStorage_Text= "Manage Site Storage";

var L_Sharing_Text= "Sharing";

var L_Settings_Text= "Settings";

var L_Remove_Text= "Remove from this list";

var L_ModerateItem_Text   = "Approve/reject";

var L_DownloadOriginal_Text = "Download Picture";

var L_EditVersion_Text= "Edit";

var L_ViewVersion_Text= "View";

var L_RestoreVersion_Text = "Restore";

var L_DeleteVersion_Text  = "Delete";

var L_EditInOIS_Text= "Edit Picture";

var L_AddToMyLinks_Text   = "Add to My Links";

var L_AddToCategory_Text  = "Submit to Portal Area";

 

=====

 

So, you can simply find the display text of the item you want to remove [from ALL sites], find its string constant (e.g. L_Subscribe_Text for "Alert Me"), find the corresponding CAMOpt call by searching for the string constant name in your AddDocLibMenuItems function -- in your custom .js file -- and comment it out.

 

Ta-da.

 

NOTE of course, that making changes directly to ows.js is not supported, and can potentially cause other unexpected problems.  Additionally, a custom .js file should only be applied to a custom site definition as described in the article above.  If you follow the rules, though, you can make a wide variety of customizations to the way that items are displayed in SharePoint sites!

Comments

  •      , 3D    , , .  ,    ,   .   Fold-Up, Pop-Up, Roll-up, Pos ,    ,    ,   , ,       , 3D     -  . http://pos-pr.ru/ e-mail: pos-pr@mail.ru
  • Anonymous
    September 20, 2007
    I don't see the "Add To My Links" menu item in the drop down menu of a document, does anybody knows why? My site is a Collaboration Portal and my library is a simple Document Library, thanks

  • Anonymous
    September 15, 2015
    Good piece - I loved the specifics ! Does someone know if I can grab a sample 2012 GSA SF-424 form to work with ?