Search This Blog

Wednesday 6 June 2012

Refer JavaScript in a SharePoint 2010 feature element.xml

Hi All,

         In this post I have discussed how to include javascript in a SP2010 feature

Steps
      1.       Create Empty SharePoint Solution
      2.       Add an Empty element
      3.       Copy the below code
<?xml version="1.0" encoding="utf-8"?>
<Elements xmlns="http://schemas.microsoft.com/sharepoint/">
  <CustomAction
    Location="ScriptLink"
    ScriptSrc="/_Layouts/HFCustomRibbonWithJS/TestScript.js" Sequence="100"></CustomAction>
    <CustomAction
       Id="TestButton"
       Location="CommandUI.Ribbon"
     >
      <CommandUIExtension>
        <CommandUIDefinitions>
          <CommandUIDefinition
           Location="Ribbon.EditingTools.CPEditTab.Paragraph.Controls._children">
            <Button
             Id="TestButton"
             Command="ShowAlert"
             Image16by16="/_layouts/images/actionseditpage16.gif"
             Image32by32="/_layouts/images/actionssettings.gif"
             LabelText="Custom Script"
             Sequence="10"
             TemplateAlias="o1"/>
          </CommandUIDefinition>
        </CommandUIDefinitions>
        <CommandUIHandlers>
          <CommandUIHandler Command="ShowAlert" CommandAction="javascript:Test();" />
        </CommandUIHandlers>
      </CommandUIExtension>
    </CustomAction>
</Elements>

      4.       Add SharePoint Layout Mapped folder in your solution and copy the javascript file in that.
      5.       Build the Solution
      6.       Deploy the Solution
      7.       Result:























You can download the complete code here.

No comments:

Post a Comment