SharePointRoot

Remove actions from the ribbon : SharePoint 2010

23 Comments

When entering text into the Rich HTML Editor with SharePoint 2010, you get a rich ‘ribbon’ experience, with a whole swag of stuff you can do – aptly titled “Format Text”.

image

This works for the Content Editor WebPart – and HTML content fields, such as Site Column – or Content Type column – like on a Publishing Page for example.

The editor includes a bunch of ‘tab groups’ (font, paragraph, etc) – with individual actions in each – like Bold, Italic, Underline, and so forth.

To *ADD* items to this set, you can use Declarative XML to create a ‘Custom Action’ – see the following for more info on how to do THAT.

How to: Modify the User Interface Using Custom Actions (MSDN)

What if you want to *REMOVE* some actions – or groups ?

And – if you need to drop actions/groups for different page types –  different Master Page and/or Page Layout ?

Well – here is some C# code using the SharePoint API that will allow you to do this.

The basic premise is :

  • Create a Visual Studio project
  • Open a Web UserControl project type
  • Add C# code to hide tabs
  • Include a reference to this user control in the Master Page

Create Visual Studio Project

The (awesome) new Visual Studio 2010 IDE has a bunch of SharePoint related project types – w00t !   More along the lines of the beloved WSPBuilder style – which I still use for SharePoint 2007 development.

  • Open Visual Studio 2010 – and click New > Project
  • Choose the SharePoint 2010 group
  • Pick the top entry “Empty SharePoint project” – give it a name : SPR.Utilities
  • Change the option button to “Deploy as a farm solution” when prompted – and click Finish.

Add a Web User Control

Now we need to add the code for the Ribbon Item Hider – we don’t actually need a ‘feature’ – just need something that will be added to the CONTROLTEMPLATES folder – located inside the 14 Hive – otherwise known as the…. (ahem) … SharePointRoot folder.

:-)

  • Right-click on the root project node (in bold) in the Solution Explorer
  • Choose Add > SharePoint Mapped Folder

image

  • When the Folder picker is shown, expand the TEMPLATE folder
  • Click on CONTROLTEMPLATES – and then OK.

This adds a location that we can add our project code – and the ASCX (web user control). 

We still need a sub-folder – otherwise the code pieces will land in the same folder as the SharePoint OOTB items – over 90 items in that folder !    *eek*

  • Right-click on the CONTROLTEMPLATES folder – and click Add > Folder
  • Change the name of the folder to be SPR.Utilities

Add the web user control

  • Right-click on the SPR.Utilities folder
  • Click Add > New Item
  • Choose the User Control item, from the SharePoint 2010 group
  • Rename it to be RibbonItemHider

Add the code – yay !

This UserControl is to live on a SharePoint Master Page, and thus there will always be a SPContext, and an underlying SPRibbon object available.

We really just need to do the following logic :

  • Grab a reference to the SPRibbon object on the page
  • Trim out the items we DON’T want to show
  • And – um, that’s it !!

Have to add a reference to the following DLL – can paste this path into the dialog shown when you choose “Add Reference”.

C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\14\ISAPI\Microsoft.Web.CommandUI.dll

And now the code :

Within the Page_Load event, just add the following code

SPRibbon ribbon = SPRibbon.GetCurrent(this.Page);
if (ribbon != null)
{

    ribbon.TrimById("xxxxxxxxxxxx");
}

You’ll get some squiggly lines underneath SPRibbon – just do a CTRL+. and choose to add the ‘using’ statement shown :

image

Obviously – you’ve probably guessed that you don’t just include xxxxxxxxxxxx in the TrimById method.  This will correlate to an entry in the following file :

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

  • Open the file in Internet Explorer – it’s pretty big, eh !
  • Do a search for “Ribbon.EditingTools.CPEditTab.Groups
  • The sub-nodes are the ones you’re interested in – a collection of GROUP nodes.
  • The groups should look familiar – they correlate to the panes on the ribbon pane :
              • Ribbon.EditingTools.CPEditTab.EditAndCheckout
              • Ribbon.EditingTools.CPEditTab.Clipboard
              • Ribbon.EditingTools.CPEditTab.Font
              • Ribbon.EditingTools.CPEditTab.Paragraph
              • Ribbon.EditingTools.CPEditTab.Styles
              • Ribbon.EditingTools.CPEditTab.Layout
              • Ribbon.EditingTools.CPEditTab.Markup
  • It follows that you can “TrimById” using these ID’s and the ribbon will be trimmed (!)

image

AND – to go further than that – you can TRIM off individual buttons – not just the group as a whole. 

Within the GROUP node, is a CONTROLS collection.  If we expand the CPEditTab.Font node – you’ll see each of the buttons as shown on screen.

image

So – the code to hide the Bold, Underline and Italic buttons – would be :

   ribbon.TrimById("Ribbon.EditingTools.CPEditTab.Font.Bold");

   ribbon.TrimById("Ribbon.EditingTools.CPEditTab.Font.Italics");

   ribbon.TrimById("Ribbon.EditingTools.CPEditTab.Font.Underline");

Easy, eh !?    Well – let’s go put it to use.

:-)

Deploy & use the control.

The amazing new SharePoint oriented functionality within Visual Studio has meant that deployment of this control could NOT be easier – I dare you to find an easier way to do it !!!

  • Right-click on the Project node – and click Deploy.
  • Ta-da !   See – I told you it was easy !

Then – we need to reference the control from within the Master Page :

  • Use SharePoint Designer 2010 to open your chosen Master Page
  • Add the following tag at the top of the Master Page

<%@ Register TagPrefix="SPR" TagName="RibbonItemHider" src="~/_controltemplates/SPR.Utilities/RibbonItemHider.ascx" %>

image

Now – we just need to “use” the tag somewhere in the Master Page.  I added it immediately after the start of the <BODY> tag – pretty sure you could add it anywhere within the HTML body – not in the HEAD section.

<SPR:RibbonItemHider id="RibbonItemHider" runat="server" />

Try it out

When you go back to SharePoint – and change the Master Page to be the one you’ve just edited – you should see that the ribbon has indeed been “trimmed” – cool, eh !?

image

See – the Bold, Italic and Underline are gone !

:-)

In closing

A few hoops to jump through – but you can now trim down other functionality using the same framework – if you’re needing to restrict what editors, authors and so forth are able to do.

Some GOOD uses of this are (for example) :

  • Remove the Edit HTML button – don’t let Content Authors muck with it.
  • Take out the SuperScript and SubScript buttons – and/or Strikeout
  • Remove the Paragraph tab – and then force the visual layout via CSS.

Pretty easy to achieve – and quite easy to narrow down what Content Authors are able to do.

Hope this was of use to you – or at the very least, a little bit ‘interesting’…

:-)

About these ads

23 thoughts on “Remove actions from the ribbon : SharePoint 2010

  1. What should I do if i want to remove “More colours” option available in Font colors and background colors?

  2. I had a quick look at the “page source” – using the IE Developer Tools – and there is a DIV that you could hide using some CSS.

    >> Ribbon.EditingTools.CPEditTab.Font.FontBackgroundColor.Menu.MsCustom

    You could try using the technique as above (from this post) – or just try via CSS. Please leave a comment if you get it working ! Thanks.

    • Hi Chris,
      Thanks alot.It worked with the above method and by using
      “Ribbon.EditingTools.CPEditTab.Font.FontBackgroundColor.Menu.MsCustom”
      for removing morecolors from fontbackground.
      many many thanks…….

  3. Hi Very well explained article.
    However in my situation I have some problems with deployment.

    I have a dev enviroment and a prod enviroment.

    So I cant deploy using right click.
    If i create a package and and deploy it and activate through powershell after i add the code to the master page nothing happen.

    i think that this could have something to do to the way i am deploying it.

    Any ideas about this? i am very new to VS 2010

  4. Hi,
    Very nice article. Exactly what I have been searching for quite some time.

    I followed each of your steps but even then the Ribbon has not been trimmed. I am very new to SP 2010 & ASP related development.
    The project has been deployed successfully and the GAC contains the SPR.Utilities dll.
    On the Sharepoint site, I did a “View Source” and the SPR.Utilities dll was not present in the source.

    Any pointers on where the problem may be?

  5. Absolutely fantastic work! I’m not a programmer but this worked like a charm! Thanks for the great post!

    —Philip

  6. Hi Chris,

    its Very nice article, this will help me alot.

    -NavazShaik

  7. Awesome… saved me lots of time!

  8. Help.. I can remove certain buttons no problem… but if I remove Fonts or Fontsize the ribbon buttons all become grey in every group.

  9. Hey
    thank’s for this tut
    but this does only local changes. The question ist how do I change this global for all Sites/Pages??

  10. Great article. I have been scouring the web trying to find an easy way to disable ribbon features when people add a content editor web part to a page and this fits the bill.

  11. This is the first article i found that actually made it happen! This affects all site when we add it as a controll on the masterpage.

    Thanks for the tutorial and step by step explanation – now i get it :-)

  12. Very very helpful, saved me tons of time.

  13. I need to hide the unpublish button and delete from both the ribbon and the context menu. Any help would be appreciated :)

  14. Hi, instead of having a usercontrol you could simply have a custom action inside a site collection feature that remove the unwanted buttons. You don’t need to add anything to the master page.

    Here is source on how to proceed : http://msdn.microsoft.com/en-us/library/ff408060.aspx

    Here are the specific controls you might want to hide : http://msdn.microsoft.com/en-us/library/ee537543.aspx

    Regards

  15. That is just great! Thanks :)

  16. I’m new to SharePoint and you just saved me a lot of time! This is the best step by step instruction on this topic!

    A big thank you!

  17. Hi,

    Is this possible to add a button to execute ps script from the server?

    Thanks

  18. Pingback: To Hide “Edit In SharePoint Designer” Option From Entire Site in SharePoint 2010 | fahadkhans

  19. that it may be hard to find a spot in the world where at least two women in the same room are not carrying some version of the luxe louis vuitton hlouis vuitton

  20. Pretty nice post. I just stumbled upon your weblog and
    wanted to say that I have truly enjoyed browsing your blog posts.
    In any case I will be subscribing to your rss feed and I hope you write again very soon!

  21. What i do not realize is in fact how you are no longer really much more
    smartly-appreciated than you might be right now. You are very intelligent.
    You realize therefore significantly when it comes to this
    matter, made me personally believe it from so many various angles.
    Its like men and women are not involved unless it is one thing to accomplish with Woman
    gaga! Your individual stuffs great. Always deal with it up!

  22. Simply desire to say your article is as amazing. The clearness in
    your post is just spectacular and i could assume
    you are an expert on this subject. Well with your permission let me to grab your feed
    to keep updated with forthcoming post. Thanks a million and please continue
    the rewarding work.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Follow

Get every new post delivered to your Inbox.

Join 30 other followers