in the MSDN article Walkthrough: Replacing a Button on the Server Ribbon
it is not as straight forward as it used to be. i can not complete it with only copy and paste the code into visual studio 2010 , then compile and deploy it to the SharePoint Server. I can't see the custom ribbon button since i use the incorrect registrationID.
first you will need to find the specific RegistrationID for Template Type that you want to custom Ribbon Tool Bar. from this link: SharePoint 2010: RegistrationId List Template Type IDs you can get the registrationID.
here is my sample code to test a button replaced with the default button.
<?xml version="1.0" encoding="utf-8"?>
<Elements xmlns="http://schemas.microsoft.com/sharepoint/">
<CustomAction Id="Ribbon.Library.Actions.ReplacementButton"
Location="CommandUI.Ribbon" RegistrationId="115"
RegistrationType="List"
Title="Replace a Ribbon Button">
<CommandUIExtension>
<CommandUIDefinitions>
<CommandUIDefinition
Location="Ribbon.Library.Actions.ConnectToClient">
<Button Id="Ribbon.Library.Actions.ConnectToClient.ReplaceNewButton"
Command="ReplacementButtonCommand"
Image16by16="/_Layouts/MyFeature/NEWITEM.GIF"
Image32by32="/_LayoutsMyFeature/NEWITEM.GIF"
LabelText="Replaced Button"
TemplateAlias="o1" />
</CommandUIDefinition>
</CommandUIDefinitions>
<!--<CommandUIHandlers>
<CommandUIHandler
Command="ReplacementButtonCommand"
CommandAction="javascript:alert('This button has been replaced with the new One.');" />
</CommandUIHandlers>-->
<CommandUIHandlers>
<CommandUIHandler
Command="ReplacementButtonCommand"
CommandAction="javascript:viewDialog('http://win-vq9f73d6i7j:28888/_layouts/FormServer.aspx?XsnLocation=http://win-vq9f73d6i7j:28888/RecyleItem/Forms/template.xsn&SaveLocation=http%3A%2F%2Fwin%2Dvq9f73d6i7j%3A28888%2FRecyleItem&ClientInstalled=true&Source=http%3A%2F%2Fwin%2Dvq9f73d6i7j%3A28888%2FRecyleItem%2FForms%2FAllItems%2Easpx&DefaultItemOpen=1')" />
</CommandUIHandlers>
</CommandUIExtension>
</CustomAction>
<CustomAction Id="Ribbon.Library.Actions.NewButton.Script"
Location="ScriptLink"
ScriptBlock="function viewDialog(linkUrl) {
var options = {
url: linkUrl,
width: 800,
height: 600,
};
SP.UI.ModalDialog.showModalDialog(options);
}"></CustomAction>
</Elements>
Please note that JavaScript can not recognize the & and i must replace it with "&" otherwise
you will get the following errors
"Error 1 Entity 'DefaultItemOpen' not defined. c:\users\administrator\documents\visual studio 2010\Projects\ReplaceARibbonButton\ReplaceARibbonButton\ReplaceARibbonButton\Elements.xml 27 357 ReplaceARibbonButton"
Error 2 Expecting ';'. c:\users\administrator\documents\visual studio 2010\Projects\ReplaceARibbonButton\ReplaceARibbonButton\ReplaceARibbonButton\Elements.xml 27 372 ReplaceARibbonButton
a blog to share Microsoft technologies Azure, DotNet, SharePoint, SQL Server,JavaScript Framework: Node.JS, Angular, React
Showing posts with label Ribbon. Show all posts
Showing posts with label Ribbon. Show all posts
Monday, February 27, 2012
Wednesday, February 15, 2012
Ribbon GroupID Interpretation in Sharepoint 2010
Since I need to dynamically disable Ribbon Menu item based on the SharePoint group.
I will create a dummie web part to verify the current user and dynamically trim off the
item or groups from the ribbon menu. you can have the idea and follow the step by step solution to create your own solution from this link Remove actions from the ribbon : SharePoint 2010
the snippet of code that will perform the action to remove item or group from the Ribbon.
SPRibbon ribbon = SPRibbon.GetCurrent(this.Page);
if (ribbon != null && GetGroupofUser())//memberInGroup)
{
//ribbon.TrimById("Ribbon.Library.Datasheet");
//ribbon.TrimById("Ribbon.Library.CustomViews");
//ribbon.TrimById("Ribbon.Library.Actions");
//ribbon.TrimById("Ribbon.Library.Share");
//ribbon.TrimById("Ribbon.Library.CustomizeLibrary");
//ribbon.TrimById("Ribbon.Library.Settings");
}
}
private bool GetGroupofUser()
{
bool isUserInGroupflag = false;
SPContext currentContext = SPContext.Current;
SPWeb spWeb = currentContext.Web;
string groupName = "My Test Group";
//Get the current logged in user
SPUser currentUser =spWeb.CurrentUser;
//Get all the user groups in the site/web
SPGroupCollection userGroups = currentUser.Groups;
//Loops through the grops and check if the user is part of given group or not.
foreach (SPGroup group in userGroups)
{
//Checking the group
if (group.Name.Contains(groupName))
isUserInGroupflag = true;
break;
}
return isUserInGroupflag ;
}
The Path to the xml file that control the Ribbon Menu Bar
C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\14\TEMPLATE\GLOBAL\XML\CMDUI.xml
The reference to know which Group or the items in the group that you need to disable
Ribbon GroupID Ribbon Group Section in Ribbon Tool Bar
Ribbon.Library.Actions Connect & Export
Ribbon.Library.Datasheet DataSheet
Ribbon.Library.CustomViews Manage Views
Ribbon.Library.Share Share & Track
Ribbon.Library.CustomizeLibrary Customize Library
Ribbon.Library.Settings Settings
Full View of Ribbon Menu Bar

Restrict View of Ribbon Menu Bar

You can find all the Ribbon Control ID from this link Default Server Ribbon Customization Locations
Update
We can even remove the server ribbon without any code. but this action will apply for every SharePoint user including the system Admin. since we will use the feature to control the appearance of
the ribbon.please view the MSDN article for the detail information Walkthrough: Removing a Button from the Server Ribbon
I will create a dummie web part to verify the current user and dynamically trim off the
item or groups from the ribbon menu. you can have the idea and follow the step by step solution to create your own solution from this link Remove actions from the ribbon : SharePoint 2010
the snippet of code that will perform the action to remove item or group from the Ribbon.
SPRibbon ribbon = SPRibbon.GetCurrent(this.Page);
if (ribbon != null && GetGroupofUser())//memberInGroup)
{
//ribbon.TrimById("Ribbon.Library.Datasheet");
//ribbon.TrimById("Ribbon.Library.CustomViews");
//ribbon.TrimById("Ribbon.Library.Actions");
//ribbon.TrimById("Ribbon.Library.Share");
//ribbon.TrimById("Ribbon.Library.CustomizeLibrary");
//ribbon.TrimById("Ribbon.Library.Settings");
}
}
private bool GetGroupofUser()
{
bool isUserInGroupflag = false;
SPContext currentContext = SPContext.Current;
SPWeb spWeb = currentContext.Web;
string groupName = "My Test Group";
//Get the current logged in user
SPUser currentUser =spWeb.CurrentUser;
//Get all the user groups in the site/web
SPGroupCollection userGroups = currentUser.Groups;
//Loops through the grops and check if the user is part of given group or not.
foreach (SPGroup group in userGroups)
{
//Checking the group
if (group.Name.Contains(groupName))
isUserInGroupflag = true;
break;
}
return isUserInGroupflag ;
}
The Path to the xml file that control the Ribbon Menu Bar
C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\14\TEMPLATE\GLOBAL\XML\CMDUI.xml
The reference to know which Group or the items in the group that you need to disable
Ribbon GroupID Ribbon Group Section in Ribbon Tool Bar
Ribbon.Library.Actions Connect & Export
Ribbon.Library.Datasheet DataSheet
Ribbon.Library.CustomViews Manage Views
Ribbon.Library.Share Share & Track
Ribbon.Library.CustomizeLibrary Customize Library
Ribbon.Library.Settings Settings
Full View of Ribbon Menu Bar
Restrict View of Ribbon Menu Bar
You can find all the Ribbon Control ID from this link Default Server Ribbon Customization Locations
Update
We can even remove the server ribbon without any code. but this action will apply for every SharePoint user including the system Admin. since we will use the feature to control the appearance of
the ribbon.please view the MSDN article for the detail information Walkthrough: Removing a Button from the Server Ribbon
Subscribe to:
Posts (Atom)