Hide/Disable Ribbon and ECB options in Document Library on a document basis


  • Hi all,

    I need both high level guidance on how to solve an issue. I hope this isn't too much detail...

    For every document library in my site, I need to evalaute each document and decide whether the user can perform certain actions, like "Edit Document" for example.  If John Doe can't do that on "Document 1', I'd like to preferably disable (or if not, hide) the "Edit Document" command in both the ribbon and the context menu.  But if he can do that on "Document 2", leave the command available.

    I'm not sure how to "package" code for this. Should I use a feature?  I'd prefer not to have to add a web part to every page that has a document library

    The decision on whether he can do it or not is NOT being done with native access controls/rights - the entire goal of my project is to determine rights another way. My coworkers have something else that renders decisions based on site visitors having a valid client certificate, and my code being able to tell what document you're trying to access, and what action ("Edit Document") you're trying to perform. I pass those three args to their code and get back a decision (deny/permit) and my code takes action, altering the interface.  That's the plan anyway...

    Based on the complexity of the above paragraph, I'd really perfer to do this server-side. And preferably when a user clicks the checkbox next to a document library item (and the ribbon appears), or when the context menu pops up.


    P.S. As background, I was using an ihttp module to achieve my overall goal, but ran into a fundamental problem: that used the URL to determine what item you were requesting and what action, but some SharePoint commands produce identical URLs as other commands, killing that approach.

    Part of my point is that I already wrote code to grab the user's identify from a certificate, determine the SP list item and action via URL, read properties from that list item as needed, and send args to the decision code my coworkers wrote.  There's a certain complexity to this and I really don't think this is a client-side operation. This server-side code could be re-used/altered for my new "feature" or whatever.

    Saturday, September 17, 2011 3:08 PM


All replies

  • Hi Gemini,

    From my understanding, you might need to disable a few options in ribbon menu when the user selects an item and disabling or not depends on a seperate logic(not with permissions).

    Im not sure but, you can try addding a javascript event handler which will trigger an event when an item is selected. the following might help u on this.

    Inside this javascript event you can get the selected ItemID by using ECMA script. Now you can call a webservice which will actually return's decision abt the user rights. U can use this value to disable the ribbon buttons i guess.

    Im not sure this willl work. Just a suggestion


    Saturday, September 17, 2011 3:31 PM
  • hi,

         You can set different Permissions levels on different Item in document Library. If Existing permision level is not serving purpose then you can create customized permission Level. check whether setting different permission level on different item will fulfil your purpose or not.



    Milan Chauhan





    Saturday, September 17, 2011 3:37 PM
  • Hi Sathish,

    I'll look into that, but I noticed that example required web parts to be added to every page for that to work.  I'm looking for a way to have this work with any document library without users needing to add anything extra.


    Monday, September 19, 2011 4:56 PM
  • There are two simple ways you have for your requirment.

    1. Create Event Handler for the List Item.

     During the addition of the document, write code to check the property and based on property set the permission to users.

    2. Create a workflow which adds / removes the permission. (this can be achieved using SharePoint Designer Impersonation Step).

    There are activities related to permissions available under impersonation step, used to add / remove / replace permissions. Create a workflow using SPD2010 and start that workflow on addition of document.

    For ref:


    Shantha Kumar .T | MCPD - SharePoint Developer 2010 | MCITP - SharePoint Administrator 2010
    (B) Shantha Kumar's Blog | (T)Follow me | (C) IOTAP
    • Marked as answer by Zizhuoye Chen Thursday, September 29, 2011 1:17 AM
    Monday, September 19, 2011 5:33 PM