SharePoint 2010 contains numerous improvements in the user interface and has been built so that it can be extended even further. By now, I’d guess that most of you have seen the Ribbon in SharePoint 2010, and many of you have probably even tried actions such as adding a button to the Ribbon. As you’ve probably learned, adding a button is quite an easy and intuitive task, but trust me: performing some of the more advanced contextual and dynamic customizations to the Ribbon can really make you sweat!
The Ribbon is a great new feature which was introduced in SharePoint 2010. In this article, we will take a look at how to add or remove custom buttons on the Ribbon in SharePoint 2010.
Challenge:
How do I add or remove a custom button on the new SharePoint 2010 Ribbon?
Solution:
Create a Custom Button on the SharePoint 2010 Ribbon
Create Feature Elements File
OK, let’s take a loot at the code which follows. What we have here is my Element.xml feature. Please pay special attention to the ID Group of my extension (red rectangle):
The schema here is basically: Ribbon.[Tab].[Group].Controls._children
And here is the resulting Ribbon group displayed in the UI:
Remove a Custom Button from the SharePoint 2010 Ribbon
At times, you may need to remove some buttons, tabs, or groups from the Ribbon, or otherwise customize the Ribbon to suit your needs. Below, what we want to do is remove the custom button from the Ribbon. This is easily accomplished adding the following code to Page_Load:
Note: You will get some squiggly lines underneath SPRibbon. Don’t worry about that, but you will need to add the “using” statement shown below:
When this code runs, the custom button will be removed from your Ribbon.
See Also:
Notes:
See the attachment for the source code and script of this example.