Remove actions from the ribbon : SharePoint 2010

By | June 18, 2010

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 FilesCommon FilesMicrosoft SharedWeb Server Extensions14ISAPIMicrosoft.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 FilesCommon FilesMicrosoft SharedWeb Server Extensions14TEMPLATEGLOBALXMLCMDUI.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’…

:-)

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

  1. jyothsna

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

    Reply
  2. Chris O'Connor

    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.

    Reply
    1. jyothsna

      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…….

      Reply
  3. Alejandro

    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

    Reply
  4. Sanjeev

    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?

    Reply
  5. pvarady3

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

    —Philip

    Reply
  6. NavazShaik

    Hi Chris,

    its Very nice article, this will help me alot.

    -NavazShaik

    Reply
  7. Sayitfast

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

    Reply
  8. Falk

    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??

    Reply
  9. David

    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.

    Reply
  10. Cristina

    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 :-)

    Reply
  11. ZyRaIN

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

    Reply
  12. SH

    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!

    Reply
  13. vincent

    Hi,

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

    Thanks

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

  15. imitation hermes bags

    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

    Reply
  16. Unknown

    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!

    Reply
  17. www.mycakeschool.com

    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!

    Reply
  18. extended warranty insurance

    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.

    Reply
  19. wln1fjc9

    家具カーペンタージョブズ}, , セックスの後に抱きしめるいくつかの時間を費やすと完全に現代的な側面もあり、ノースダコタ州マイノット州立大学の心理学者デビッド·屋根は語った。}, [url=http://www.westernpaballers.com/厚底パンプス-c-1_150.html][b]厚底パンプス[/b][/url], キャノンは、GLAのために同じようなピンチを期待しています。}, [url=http://www.primmoapps.com/kitson-キットソン-c-614_644_816.html][b]KITSON キットソン[/b][/url], [url=http://www.primmoapps.com/アバクロンビーフィッチ-メンズ zipパーカー-1222320128050-アバクロ-abercrombie-fitch-p-14947.html][b]アバクロンビー&フィッチ メンズ Zipパーカー 122-232-0128-050 【アバクロ Abercrombie & Fitch】[/b][/url], 現在のタグのほかに、狂犬病が含まれ、私の犬は彼の名前とその上に私の電話番号を持つタグを持っています。| 彼はイエス、緩い得ているが、名前タグが役立ちます。}, [url=http://www.westernpaballers.com/ヴァンパイア骑士-コスプレ衣装-c-4_105.html]http://www.westernpaballers.com/ヴァンパイア骑士-コスプレ衣装-c-4_105.html[/url], [url=http://www.westernpaballers.com/超合金初音 初音家族 コスプレ衣装 7セット-p-5637.html][b]超合金初音 初音家族 コスプレ衣装 7セット[/b][/url], オフィサーウィルソンは、役員が戻って彼に運転したとき、ブラウンは彼の顔を殴ったことを大陪審に語った。}, [url=http://www.primmoapps.com/セリーヌ-celine-腕時計-時計-レディース-c77111014-smtbkw2-p-21119.html][b]セリーヌ CELINE 腕時計 時計 レディース C77111014 【smtb-k】【w2】[/b][/url], [url=http://www.westernpaballers.com/dgrayman ディーグレイマン 黒の教団の徽章-p-348.html][b]D.Gray-man ディーグレイマン 黒の教団の徽章[/b][/url], 私たちは、60年代に行われ、非常に寒かった私たちの地下室をやり直ししようとしている。| 私たちは、壁、スタッド、その後蒸気バリアと乾式壁にタイベックやタール紙を適用するように言われてきた。| 私たちは(私たちが引退し、限られた収入されている)ため、コストのグラスファイバーバット断熱材を使用する予定。| 私たちは、スプレー泡を行い、すべての水蒸気バリアなどを心配する必要がないようにするのが大好きだが、我々は予算外Styrofoamsはあなたがそれぞれの作品をカットする必要があり、時間によって、多くの作業のように思えるです。| (中央に16インチを絶縁し、多分乾式壁を設置するが、テーピングと仕上げていない)間柱材。| 我々はタール紙を使用している場合、我々はそれをオーバーラップしないか、あなたはタイベックの縫い目を行うように、我々は非常にそれをテープで固定しますか? 私たちは、紙で右階へ行くのですか、絶縁体と同じように、私たちはそれ地面から足続けるのですか? すべてのヘルプは、提案が非常に高く評価されている。}, , [url=http://www.ayudantedelabuelo.com/basketball-c-5_74_79.html][b]BASKETBALL[/b][/url], [url=http://www.ayudantedelabuelo.com/nike-air-jordan-7-retro-whtoblublkinfrrd-304775105-p-4238.html][b]”NIKE AIR JORDAN 7 RETRO wht/o.blu-blk-infrrd 304775-105″[/b][/url], , [url=http://www.primmoapps.com/アリミノ-スパイス-ミスト-モイスチュア-250ml-リフィル-p-21325.html][b]アリミノ スパイス ミスト モイスチュア 250ml (リフィル)[/b][/url], あなたが税の行為に出席した場合。}, [url=http://www.primmoapps.com/ルシードlucid-c-609_629_653_1197.html][b]ルシード(Lucid)[/b][/url], [url=http://www.westernpaballers.com/カンガルー マスコット 成人用 着ぐるみ-p-6880.html][b]カンガルー マスコット 成人用 着ぐるみ[/b][/url], 「彼らは素晴らしい仲間であり、私はそれは素晴らしいイベントだと聞いていますが、彼らは水のスイミングロイヤリティ開かれているように私もシェリーとタミーのためのより多く驚きましたので、それは女の子と一緒に泳ぐのはいいだっただろう」と彼は言った。}, パイロットチームは、ローマの近くに武装偵察任務のために、ナポリの近くに、ピニャターロ·マッジョーレから離陸した。| パイロットは8 10ドイツのメッサーシュミットBf109戦闘機によって摘発された。}, 蜂巣炎は細菌による皮膚感染症である。| 状態は連鎖球菌やブドウ球菌である原因となる細菌の最も一般的な形態、。}, 写真:サンティノは訪問者を攻撃する方法}

    Reply
  20. spx|dnjurhsodfc

    You dont want your personal things jutting out of your purse or briefcase. Keep your bag clean on the inside, especially if it doesnt have a zipper, which allows others to catch a glimpse inside from time to time. Williams also advises professionals not to wear knapsacks because it looks too collegiate., [url=http://www.citizensforthetrain.com/barbour-waterproof-jackets-c-8_12.html][b]Barbour Waterproof Jackets[/b][/url], When the women arrived, some raced for a corner spot., [url=http://www.citizensforthetrain.com/mens-barbour-new-eskdale-quilted-jacket-black-dark-brown-forest-navy-p-417.html][b]Men’s Barbour New Eskdale Quilted Jacket Black Dark Brown Forest Navy [/b][/url], MOMENTUM COACH: I am known as Dr. Mo by coaching clients, members on the maintainmomentum website, colleagues and thousands of people around the world who read my morning email AmMo, and my blog, posts on facebook, and messages on Twitter. I have dedicated my life to helping individuals, groups, and teams keep the gains of their initiatives, projects and programs going over the long haul.锘? Ways to Have a Fun and Frugal Halloween, [url=http://www.mdsafedefense.com/christian-louboutin-body-strass-100mm-bridal-shoes-poudre-christian-louboutin-outlet-p-116.html][b]Christian Louboutin BODY STRASS 100mm Bridal Shoes POUDRE Christian Louboutin Outlet[/b][/url], [url=http://www.mdsafedefense.com/christian-louboutin-sneakers-c-1_5.html][b]Christian Louboutin Sneakers[/b][/url], [url=http://www.mdsafedefense.com/christian-louboutin-dada-veau-velours-loafer-shoes-beige-christian-louboutin-outlet-p-19.html][b]Christian Louboutin DADA VEAU VELOURS Loafer Shoes BEIGE Christian Louboutin Outlet[/b][/url], 5. Buy Yourself New Workout Clothes, [url=http://www.dungeonrockracing.com/men-s-burton-snowboard/burton-jeremy-jones-snowboards.html][b]Burton Jeremy Jones Snowboards[/b][/url], [url=http://www.dungeonrockracing.com/burton-lipstick-snowboard-good-market-women-burton-lipstick-snowboards.html][b]Burton Lipstick Snowboard Good Market Women Burton Lipstick Snowboards[/b][/url], i think after having a baby u get so excited u lost a lot of weight then u get comfortable eat how you used it creeps back up. ok no more tweeting and procrastinating! LOL Glad some of u moms can relate.锘緾lothes at Home for Cheap, [url=http://www.mdsafedefense.com/christian-louboutin-harvanana-calf-loafer-shoes-black-christian-louboutin-outlet-p-29.html][b]Christian Louboutin HARVANANA CALF Loafer Shoes BLACK Christian Louboutin Outlet[/b][/url],[url=http://www.dungeonrockracing.com/burton-prowess-snowboard-jacket-womens-selling-spirit-camo-women-s-burton-snowboards-jacket.html][b]Burton Prowess Snowboard Jacket – WoMens Selling Spirit Camo WoMen’s Burton Snowboards Jacket[/b][/url], The white coat remains a symbol for the medical profession, closely followed by the stethoscope. The wearing of white coats originated in the 19th century. Ironically, they were introduced in order to prevent cross contamination on the wards. They heralded an era in which improved understanding of hygiene meant that hospitals were no longer synonymous with death. At the time doctors were also receiving particularly bad press as scientists repeatedly proved their cures to be useless. Doctors realised that the future of medicine lay in science and turned to the laboratory to provide new answers. Aiming to win back public trust doctors wore a white coat in an attempt to show their allegiance with modern science.[1] More recently, elderly patients were shown to favour doctors wearing a white coat, as it made the doctor easy to identify.[2] (Although one can certainly walk around a hospital and find many staff in a white coat who aren doctors.) White coats have fallen out of favour over the past decade, however, as fears about infection have grown, and providing clean white coats daily has been thought to be too impractical. Few doctors mourn their loss, believing them to be hot and uncomfortable, although some women do miss the storage space., [url=http://www.citizensforthetrain.com/barbour-newton-quilt-barbour-jacket-outlet-p-1515.html][b]Barbour Newton Quilt Barbour Jacket Outlet[/b][/url], [url=http://www.mdsafedefense.com/christian-louboutin-follies-resille-100mm-pumps-shoes-naturalblack-christian-louboutin-outlet-p-247.html][b]Christian Louboutin FOLLIES RESILLE 100mm Pumps Shoes NATURAL/BLACK Christian Louboutin Outlet[/b][/url], Mods reserve the right to remove content or restrict users posting privileges as necessary if it is deemed detrimental to the subreddit or to the experience of others. more >>, [url=http://www.dungeonrockracing.com/burton-no-fish-snowboard-good-market-156cm.html]http://www.dungeonrockracing.com/burton-no-fish-snowboard-good-market-156cm.html[/url], [url=http://www.dungeonrockracing.com/men-s-burton-snowboard/burton-fish-snowboards.html][b]Burton Fish Snowboards[/b][/url], [url=http://www.dungeonrockracing.com/burton-amped-snowboard-jacket-kids-youth-popular-atlantic-kids-burton-snowboard-jacket.html][b]Burton Amped Snowboard Jacket – Kids Youth Popular Atlantic Kids Burton Snowboard Jacket[/b][/url], [url=http://www.citizensforthetrain.com/barbour-bedale-jackets-c-1_37.html][b]Barbour Bedale Jackets[/b][/url], A claim that you can make significant income in an Internet business without owning a computer is ridiculous. Although you may not need a computer to talk to someone about buying a web site, if you dont own a computer and use it regularly on the Internet, you arent going to know enough about the Internet to be effective at selling any legitimate Internet product or service., August Bonus, purchase this property in the month of August and receive a bonus $2,000.00 flight centre voucher., by Charlie Schroeder and Ryan M. Noll, There was also a bullying incident the year before. Another parent informed school officials that Ally was being bullied on the online site.

    Reply

Leave a Reply

Your email address will not be published. Required fields are marked *