چند روز پیش در جلسه ای بودم و داشتم در جمعی از مدیران محترم از امکانات شیرپونت صحبت می کردم و از شما چه پنهان صفحه ای رو که طراحی می کردم توضیح می دادم که در این میان یکی از مدیران سئوالی از من پرسید که تا اون لحظه بهش فکر نکرده بودم واون هم این بود که اگر قرار دسترسی کابر خاصی محدود باشه چرا در ribbon صفحه باید کلی از کلیدهای امکانات غیر فعال را مشاهده کنه !!!
البته من با این نظر موافق نیستم اما خوب چه می شه کرد گاهی وقتی خواسته های این مدیران محترم باعث می شه به مواردی که شاید طراحان شیرپونت در مایکروسافت فکر نکردن ما فکر کنیم و دستی در ساختار این سیستم ببریم برای همین چند شیوه برای ویرایش ribbon پیدا کردم که براتون می ذارم .امیدوارم برای شما هم مفید باشه:
Remove actions from the ribbon : SharePoint 2010
Remove actions from the ribbon : SharePoint 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”.
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 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.
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.
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*
Add the web user control
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 :
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 :
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
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.
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 !!!
Then – we need to reference the control from within the Master Page :
<%@ Register TagPrefix="SPR" TagName="RibbonItemHider" src="~/_controltemplates/SPR.Utilities/RibbonItemHider.ascx" %>
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 !?
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) :
Pretty easy to achieve – and quite easy to narrow down what Content Authors are able to do.