I am trying to create a custom ribbon and in my project I have created a JavaScript file.
From this and this question I was able to figure out that I can use <CustomAction>
tag to import the JavaScript file.
<CustomAction Id="Ribbon.Library.Actions.Scripts"
Location ="ScriptLink" ScriptSrc="/_layouts/MyJSFile.js" />
Now my Elements.xml
looks like this:
<?xml version="1.0" encoding="utf-8"?>
<Elements xmlns="http://schemas.microsoft.com/sharepoint/">
<CustomAction Id="Ribbon.Library.Actions.Scripts" Location="ScriptLink"
ScriptSrc="/_layouts/CustomRibbonButton/JavaScript1.js" />
<CustomAction
Id="Ribbon.Library.Actions.AddAButton"
Location="CommandUI.Ribbon"
RegistrationId="101" RegistrationType="List"
Title="Add a Ribbon Button">
<CommandUIExtension>
<CommandUIDefinitions>
<CommandUIDefinition
Location="Ribbon.Library.Share.Controls._children">
<Button Id="Ribbon.Library.Share.NewRibbonButton"
Command="NewRibbonButtonCommand"
Image16by16="_layouts/15/images/placeholder16x16.png"
Image32by32="_layouts/15/images/placeholder32x32.png"
LabelText="Hello World"
TemplateAlias="o2" />
</CommandUIDefinition>
</CommandUIDefinitions>
<CommandUIHandlers>
<CommandUIHandler
Command="NewRibbonButtonCommand"
CommandAction="javascript:getFiles()" />
</CommandUIHandlers>
</CommandUIExtension>
</CustomAction>
</Elements>
When I load my page in IE in Network tab of IE developer tools I can see 404 error that it is not able to find the path /_layouts/customribbonbutton/javascript1.js
. I updated my <CustomAction>
tag to this:
<CustomAction Id="Ribbon.Library.Actions.Scripts" Location="ScriptLink"
ScriptSrc="/_layouts/JavaScript1.js" />
But I still get the same 404 error, albeit for different path.
What am I doing wrong here?