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) ;-)
Showing posts with label Ribbon Bar. Show all posts
Showing posts with label Ribbon Bar. Show all posts
Tuesday, November 24, 2015
SharePoint 2010 - Tutorial - Hiding Ribbon Items
Labels:
C#,
CSharp,
Master Page,
Ribbon Bar,
SharePoint 2010,
Tutorial
Friday, June 13, 2014
SharePoint 2010 - Building Custom Actions in Visual Studio
Today I will show how you can add custom actions to the ribbon bar and the edit control block in SharePoint.
We have to start with creating an empty element in the project. Then replace the text in the xml file with this:
<?xml version="1.0" encoding="utf-8"?>
<Elements xmlns="http://schemas.microsoft.com/sharepoint/">
<CustomAction
Description="Approve Documents"
Title="Approve Documents"
Id="RibbonDocumentsManageApproveDocuments"
Location="CommandUI.Ribbon"
RegistrationId="10000"
RegistrationType="List"
Sequence="0"
xmlns="http://schemas.microsoft.com/sharepoint/">
<CommandUIExtension xmlns="http://schemas.microsoft.com/sharepoint/">
<!-- Define the (UI) button to be used for this custom action -->
<CommandUIDefinitions>
<CommandUIDefinition Location="Ribbon.Documents.Manage.Controls._children">
<Button Id="Ribbon.Documents.Manage.ApproveDocuments"
Command="{4E2F5DC0-FE2C-4466-BB2D-3ED0D1917763}"
Image32by32="~site/_layouts/Images/SharePoint-Z-Drive-Project/approve_document_32x32.png"
Image16by16="~site/_layouts/Images/SharePoint-Z-Drive-Project/approve_document_16x16.png"
Sequence="0"
LabelText="Approve Documents"
Description="Approve Documents"
TemplateAlias="o1" />
</CommandUIDefinition>
</CommandUIDefinitions>
<CommandUIHandlers>
<!-- Define the action expected on the button click -->
<CommandUIHandler Command="{4E2F5DC0-FE2C-4466-BB2D-3ED0D1917763}" CommandAction="javascript:window.open('http://www.bing.com/search?q='.concat(escape(document.title)))" />
</CommandUIHandlers>
</CommandUIExtension>
</CustomAction>
<CustomAction
Description="Approve Document"
Title="Approve Document"
Id="EditControlBlockApproveDocument"
Location="EditControlBlock"
RegistrationId="10000"
RegistrationType="List"
ImageUrl="~site/_layouts/Images/SharePoint-Z-Drive-Project/approve_document_16x16.png"
Sequence="1101"
xmlns="http://schemas.microsoft.com/sharepoint/">
<CommandUIExtension xmlns="http://schemas.microsoft.com/sharepoint/">
<!-- Define the (UI) button to be used for this custom action -->
<CommandUIDefinitions>
<CommandUIDefinition Location="EditControlBlock">
<Button Id="EditControlBlock.ApproveDocument"
Command="{F8C45D3A-A00D-4412-91BB-C49D75A36F3A}"
Sequence="1101"
LabelText="Approve Document"
Description="Approve Document"
TemplateAlias="o2" />
</CommandUIDefinition>
</CommandUIDefinitions>
<CommandUIHandlers>
<!-- Define the action expected on the button click -->
<CommandUIHandler Command="{F8C45D3A-A00D-4412-91BB-C49D75A36F3A}" CommandAction="javascript:window.open('http://www.bing.com/')" />
</CommandUIHandlers>
</CommandUIExtension>
</CustomAction>
</Elements>
We have to start with creating an empty element in the project. Then replace the text in the xml file with this:
<?xml version="1.0" encoding="utf-8"?>
<Elements xmlns="http://schemas.microsoft.com/sharepoint/">
<CustomAction
Description="Approve Documents"
Title="Approve Documents"
Id="RibbonDocumentsManageApproveDocuments"
Location="CommandUI.Ribbon"
RegistrationId="10000"
RegistrationType="List"
Sequence="0"
xmlns="http://schemas.microsoft.com/sharepoint/">
<CommandUIExtension xmlns="http://schemas.microsoft.com/sharepoint/">
<!-- Define the (UI) button to be used for this custom action -->
<CommandUIDefinitions>
<CommandUIDefinition Location="Ribbon.Documents.Manage.Controls._children">
<Button Id="Ribbon.Documents.Manage.ApproveDocuments"
Command="{4E2F5DC0-FE2C-4466-BB2D-3ED0D1917763}"
Image32by32="~site/_layouts/Images/SharePoint-Z-Drive-Project/approve_document_32x32.png"
Image16by16="~site/_layouts/Images/SharePoint-Z-Drive-Project/approve_document_16x16.png"
Sequence="0"
LabelText="Approve Documents"
Description="Approve Documents"
TemplateAlias="o1" />
</CommandUIDefinition>
</CommandUIDefinitions>
<CommandUIHandlers>
<!-- Define the action expected on the button click -->
<CommandUIHandler Command="{4E2F5DC0-FE2C-4466-BB2D-3ED0D1917763}" CommandAction="javascript:window.open('http://www.bing.com/search?q='.concat(escape(document.title)))" />
</CommandUIHandlers>
</CommandUIExtension>
</CustomAction>
<CustomAction
Description="Approve Document"
Title="Approve Document"
Id="EditControlBlockApproveDocument"
Location="EditControlBlock"
RegistrationId="10000"
RegistrationType="List"
ImageUrl="~site/_layouts/Images/SharePoint-Z-Drive-Project/approve_document_16x16.png"
Sequence="1101"
xmlns="http://schemas.microsoft.com/sharepoint/">
<CommandUIExtension xmlns="http://schemas.microsoft.com/sharepoint/">
<!-- Define the (UI) button to be used for this custom action -->
<CommandUIDefinitions>
<CommandUIDefinition Location="EditControlBlock">
<Button Id="EditControlBlock.ApproveDocument"
Command="{F8C45D3A-A00D-4412-91BB-C49D75A36F3A}"
Sequence="1101"
LabelText="Approve Document"
Description="Approve Document"
TemplateAlias="o2" />
</CommandUIDefinition>
</CommandUIDefinitions>
<CommandUIHandlers>
<!-- Define the action expected on the button click -->
<CommandUIHandler Command="{F8C45D3A-A00D-4412-91BB-C49D75A36F3A}" CommandAction="javascript:window.open('http://www.bing.com/')" />
</CommandUIHandlers>
</CommandUIExtension>
</CustomAction>
</Elements>
The first custom action is to add the button to ribbon bar in the document library.
The second custom action will add the button to the edit control block of an item.
Labels:
C#,
CSharp,
Custom Actions,
Edit Control Block,
Ribbon Bar,
SharePoint 2010,
Visual Studio 2010,
XML
Subscribe to:
Posts (Atom)







