Today I want to show you, how you can hide items from the ribbon bar.
We start as usual with an empty SharePoint project.
Add a new item to the project: User Control and give it a name (i.e. "RibbonControl.ascx").
Add the "Microsoft.Web.CommandUI.dll" reference from "c:\program files\common files\microsoft shared\web server extensions\14\isapi"-folder to your project.
Then open the code-behind file. In my case it is "RibbonControl.ascx.cs".
Add the following namespaces to your code:
using Microsoft.SharePoint;
using Microsoft.SharePoint.WebControls;
using Microsoft.Web.CommandUI;
Use the ribbon.TrimById() method to hide items in the ribbon bar.
Here are some examples. See a full list of all ribbon items here:
https://msdn.microsoft.com/en-us/library/office/ee537543(v=office.14).aspx
protected void Page_Load(object sender, EventArgs e)
{
try
{
SPRibbon ribbon = SPRibbon.GetCurrent(this.Page);
using (SPSite site = SPContext.Current.Site)
{
//"Documents"-tab
ribbon.TrimById("Ribbon.Documents.Copies");
ribbon.TrimById("Ribbon.Documents.Workflow");
ribbon.TrimById("Ribbon.Documents.Share");
ribbon.TrimById("Ribbon.Documents.Manage.ManagePermissions");
ribbon.TrimById("Ribbon.Documents.TagsAndNotes");
//"Library"-tab
ribbon.TrimById("Ribbon.Library.ViewFormat");
ribbon.TrimById("Ribbon.Library.Share");
ribbon.TrimById("Ribbon.Library.Datasheet");
ribbon.TrimById("Ribbon.Library.Actions");
ribbon.TrimById("Ribbon.Library.CustomizeLibrary");
}
}
catch (Exception exp)
{
throw exp;
}
}
Then your user control is ready now.
The next step is to add your user control whereever you need it, i.e. to your master page, page, web parts etc..
To deploy a custom master page, see my blog post http://me-and-my-sharepoint.blogspot.de/2015/11/sharepoint-2010-tutorial-deploying.html
You can also use SharePoint Designer to modify a page.
I deployed a custom master page to hide ribbon items in all document libraries in a site collection.
Register the user control at the top of the page:
<%@ Register TagPrefix="custom" TagName="RibbonBarControl" src="~/_controltemplates/TestRibbonsHideProject/RibbonControl.ascx" %>
We've created user control for SharePoint 2010, registered it on the page. Now, the final step is to include the user control in the page itself:
<custom:RibbonControl id="RibbonControl1" runat="server"></custom:RibbonControl>
Then we are ready to deploy the solution.
See the ribbon bar before activating our user control:
Then afterwards:
Hope you enjoyed it. Feel free to leave a comment, if you like (or not) ;-)
No comments:
Post a Comment