Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

I want to hide a SharePoint 2010 ribbon button for a list based on SharePoint groups.

SPSecurity.RunWithElevatedPrivileges(delegate()
{            
    using (SPSite site = new SPSite(SPContext.Current.Web.Url))
    using (SPWeb web = site.OpenWeb())
    {
        SPList list = web.Lists.TryGetList("BMS");

        if (list != null)
        {

            SPRibbon ribbon = SPRibbon.GetCurrent(this.Page);
            string user = HttpContext.Current.User.Identity.Name;
            SPWebLocation = web;
            if (ribbon != null)
            {
                string Editorsgroup = "Editors";

                if (isUserInGroup(Editorsgroup, user))
                {
                    ribbon.TrimById("Ribbon.Documents.Workflow.CancelApproval");
                    ribbon.TrimById("Ribbon.Documents.Workflow.Unpublish");
                    ribbon.TrimById("Ribbon.Documents.Workflow.Moderate");
                }
            }
        }
    }
});

but it's hiding the ribbon for all pages and all lists.

I need to hide the ribbon button for only one list.

Is there any alternate way to dynamically hide the ribbon button for a list?

I need to hide the ribbon button programmatically.

share|improve this question

2 Answers 2

up vote 1 down vote accepted

This product actually allows you to hide or disable buttons (based on SharePoint permissions) on the Ribbon panel: http://www.xstreamsoftware.com/Sharepointribbonizer.htm

share|improve this answer
    
i tried the product but after i apply the conditions for ribbon, the total ribbon bar is not working like some times the ribbon bar is not showing, some time the ribbon buttons are not working. –  kavalirakesh Mar 21 '13 at 9:17
    
Which browser were you using and what version? –  Will Au Mar 21 '13 at 17:35
    
i tested on IE8 an firefox 18 and chrome, i all 3 browsers it giving same problem. if i remove xtream ribbonizer settings or rules, the ribbon bar working normally. –  kavalirakesh Mar 21 '13 at 21:00
    
I just tried the product with the following browsers on my VM: IE8, Firefox 19, and Chrome. It works on all of them. Can you tell me which exact settings you applied that caused your issues? I can try to replicate on my side here... –  Will Au Mar 22 '13 at 20:14
    
the product is working may be my virtual machine has problem. –  kavalirakesh Mar 22 '13 at 22:01

What you are checking is only if the specified list exists on the web, not that you are actually on a page with a view of that list.

Maybe javascript is the way to go for this case? Hiding the button only on your pages that contains a listview for your list?

On this page you will find an example of using Javascript. The key is to identify the correct item to hide from the DOM. Usally you can use the id of the link as in the example above.

Then you will need to add this script to your pages as Mike shows you in this article

share|improve this answer
    
can you give me some example links to hide SharePoint list item with java script programmatically. i tried googling but it shows this way only. i need to hide particular list ribbon button. –  kavalirakesh Feb 26 '13 at 10:51
    
Please see my updated answer above –  Robert Lindgren Feb 26 '13 at 11:36

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.