Wednesday, February 15, 2012

Ribbon GroupID Interpretation in Sharepoint 2010

Since I need to dynamically disable Ribbon Menu item based on the SharePoint group


I will create a dummie web part to verify the current user and  dynamically trim off the
item or groups from the ribbon menu. you can have the idea and follow the step by step solution to create your own solution from this link   Remove actions from the ribbon : SharePoint 2010

the snippet of code that will perform the action to remove item or group from the Ribbon.
   
            SPRibbon ribbon = SPRibbon.GetCurrent(this.Page);
            if (ribbon != null && GetGroupofUser())//memberInGroup)
            {
                //ribbon.TrimById("Ribbon.Library.Datasheet");
                //ribbon.TrimById("Ribbon.Library.CustomViews");
                //ribbon.TrimById("Ribbon.Library.Actions");
                //ribbon.TrimById("Ribbon.Library.Share");
                //ribbon.TrimById("Ribbon.Library.CustomizeLibrary");
                //ribbon.TrimById("Ribbon.Library.Settings");
            }
}

        private bool GetGroupofUser()
        {
            bool isUserInGroupflag = false;
            SPContext currentContext = SPContext.Current;
            SPWeb spWeb = currentContext.Web;
            string groupName = "My Test Group";
            //Get the current logged in user               
            SPUser currentUser =spWeb.CurrentUser;

            //Get all the user groups in the site/web               
            SPGroupCollection userGroups = currentUser.Groups;
            //Loops through the grops and check if the user is part of given group or not.               
            foreach (SPGroup group in userGroups)
            {
                //Checking the group                   
                if (group.Name.Contains(groupName))
                    isUserInGroupflag = true;
                break;
            }

            return isUserInGroupflag ;
        }
The Path to the xml file that control the Ribbon Menu Bar

C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\14\TEMPLATE\GLOBAL\XML\CMDUI.xml

The reference to know which Group or the items in the group that you need to disable

Ribbon GroupID                            Ribbon Group Section in Ribbon Tool Bar
Ribbon.Library.Actions                           Connect & Export
Ribbon.Library.Datasheet                        DataSheet
Ribbon.Library.CustomViews                 Manage Views
Ribbon.Library.Share                              Share & Track
Ribbon.Library.CustomizeLibrary          Customize Library
Ribbon.Library.Settings                          Settings

 Full View of Ribbon Menu Bar


Restrict View of Ribbon Menu Bar




You can find all the Ribbon Control ID from this link Default Server Ribbon Customization Locations


Update

We can even remove the server ribbon without any code. but this action will apply for every SharePoint user including the system Admin. since we will use the feature to control the appearance of
the ribbon.please view the MSDN article for the detail information Walkthrough: Removing a Button from the Server Ribbon

No comments:

Post a Comment