Hiding ECB menus selectively based on an item property

I needed to hide context menu item “Edit Document”, for files of a particular type (which SharePoint determines from the file extension). Here's is how I achieved it :

The menu Item “Edit Document” is rendered via AddDocLibMenuItems function in CORE.JS. Possible approaches to achieve this override in a supported way :

Option1 :

a)Create a customCORE.JS

b)Add extra code, explained in next few lines below in AddDocLibMenuItems function

c)Create a custom masterpage and add a scriptlink for customCORE.js


Similar to above option, but instead of creating  customCORE.js, we can override either the  AddDocLibMenuItems or add an implementation of Custom_AddDocLibMenuItems on the masterpage itself in a script tag, after the scriptlink for CORE.js <SharePoint:ScriptLink language="javascript" name="core.js" Defer="true" runat="server" />)


If the change is needed only on one page(View Page of one Library), add a CEWP with an implementation of Custom_AddDocLibMenuItems, which is identical to AddDocLibMenuItems from CORE.js + additional check for the file extension talked about below.

We can override the AddDocLibMenuItems function to not to render the “Edit Document” menu, when the file is of a particular file extension.(In below example, I am checking if it’s a .txt file, then skip the part that renders the “Edit Document” menu.)Below highlighted, is the code that I put in the AddDocLibMenuItems in CORE.js

function AddDocLibMenuItems(m, ctx)





            var strExt  = GetAttributeFromItemTable(itemTable, "Ext", "FileType"); 

            if(strExt != "txt")


                        var   objEditor=StsOpenEnsureEx(currentItemOpenControl+".3");

                        if (objEditor !=null




                  if (strDisplayText !="")


                        strAction="editDocumentWithProgID2('"+currentItemFileUrl+"', '"+currentItemProgId+"', '"

+currentItemOpenControl+"', '"+bIsCheckout+"', '"+ctx.HttpRoot+"', '"+currentItemCheckedoutToLocal+"')";


                              menuOption=CAMOpt(m, strDisplayText, strAction, strImagePath, null, 240);









HTH & Happy Customizing SharePoint !!


Comments (3)
  1. sp2010dev says:

    Hello, does this work with new 2010 interface?

    I tried to implement this, but I got no changes there :/

  2. Sanjana says:

    I want to hide context menu items only for a particular document library. can you please suggest the steps to be followed.

  3. Derf says:


Comments are closed.

Skip to main content