0

I am trying to add a custom button in the display form for a document library item. I managed to do it for Display form for a list item, but can't adapt it to a document library item, anyone have ideas what is needed to be change in order to work for document library item? I believe something in the Location attribute should be changed, but not sure in what way. Below you can see sample for the list item.

<CustomAction
Description="Search Title on Bing"
Title="Bing It!"
Id="{E538E8C7-65DA-454E-AD87-4A603B6CC569}"
Location="CommandUI.Ribbon.DisplayForm"
RegistrationId="100"
RegistrationType="List"
Sequence="0"
Rights="ViewListItems"
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.ListForm.Display.Manage.Controls._children">
<Button Id="{B511A716-54FF-4EAE-9CBE-EA02B51B626E}"
Command="{4E2F5DC0-FE2C-4466-BB2D-3ED0D1917763}"
Image32by32="_layouts/15/images/placeholder32x32.png"
Sequence="0"
LabelText="Bing"
Description="Search Title on Bing"
TemplateAlias="o1"
/>
</CommandUIDefinition>
</CommandUIDefinitions>
<CommandUIHandlers>
<!-- Define the action expected on the button click -->
<CommandUIHandler 
Command="{4E2F5DC0-FE2C-4466-BB2D-3ED0D1917763}"
CommandAction="javascript:openDialog(); 
function openDialog() { 
alert('Hello');      
}; 
}
"/>
</CommandUIHandlers>
</CommandUIExtension>
</CustomAction>
</Elements>

2 Answers 2

0

Yes you are right it with the Location attribute and according to you snippet Location="CommandUI.Ribbon.DisplayForm" means that a button will be added on display form. And Location="Ribbon.ListForm.Display.Manage.Controls._children" of CommandUIDefinition specifies that it will be added to the Manage tab of the Display form.

To change the custom action to appear on document library view you should try with CustomAction Location to CommandUI.Ribbon.ListView and in CommandUIDefinition set Location="Ribbon.Tabs._children"

2
  • The desired result is to show the button in a display form for item in the Document Library, not to the entire Document Library. I managed to do it and posted code snippet below. Surprisingly, I needed to change other attributes, not the 'Location" one. Have a look, it may be useful to you one day. Have a nice day =) Oct 22, 2018 at 13:55
  • Missed the list item, and document item. And assumed you were looking for entire library.Never mind.
    – Sunil Sahu
    Oct 22, 2018 at 14:06
0

I managed to make it. In the registrationID I set the contenttypeID which I am using and in RegistrationType I changed it to be ContentType. This did the trick! Here is a working sample:

<CustomAction
Description="Search Title on Bing"
Title="Bing It!"
Id="{E538E8C7-65DA-454E-AD87-4A603B6CC569}"
Location="CommandUI.Ribbon.DisplayForm"
RegistrationId="IdOfTheContentType"
RegistrationType="ContentType"
Sequence="0"
Rights="ViewListItems"
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.ListForm.Display.Manage.Controls._children">
<Button Id="{B511A716-54FF-4EAE-9CBE-EA02B51B626E}"
Command="{4E2F5DC0-FE2C-4466-BB2D-3ED0D1917763}"
Image32by32="_layouts/15/images/placeholder32x32.png"
Sequence="0"
LabelText="Bing"
Description="Search Title on Bing"
TemplateAlias="o1"
/>
</CommandUIDefinition>
</CommandUIDefinitions>
<CommandUIHandlers>
<!-- Define the action expected on the button click -->
<CommandUIHandler 
Command="{4E2F5DC0-FE2C-4466-BB2D-3ED0D1917763}"
CommandAction="javascript:openDialog(); 
function openDialog() { 
alert('Hello');      
}; 
}
"/>
</CommandUIHandlers>
</CommandUIExtension>
</CustomAction>
</Elements>

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.