There are plenty or articles on how to do this. This is more of a note for myself, as I have to “re-learn” this every time I need to customize SharePoint. There are 2 ways (that I know of) that you can add code to every page in SharePoint 2010, 1 by the AdditionalPageHead delegate control, or ,2 by Custom Action. This article is about #2 using a Custom Action. This article is about #1 – Delegate Controls
- Start Visual Studio, and create a new Empty SharePoint Project (uncheck the Create Directory for Solution because you salways create the destination directory yourself)
- Deploy as a Farm Solution (I have not figured what you can and can’t do with sandboxed solutions yet)
- RightCLick the Project and select Add Module and name the Module at the bottom (I name the Module the name of the Document Library where I want to put the file)
- Chop up the elements.xml file. The final should look like this below:
is changed to (Url is the Doc Library where the file will be added) is changed to (Remove the path from Url and add the “GhostableInLibrary” part)
<Elements xmlns="http://schemas.microsoft.com/sharepoint/"> <Module Name="Test" Url="Test"> <File Path="Test\jquery-1.7.min.js" Url="jquery-1.7.min.js" Type="GhostableInLibrary" /> </Module> </Elements>
Now you need to the code to add the file to the top of every page, add the “CustomAction” stuff below
<CustomAction ScriptSrc="~SiteCollection/Test/jquery-1.7.min.js" Location="ScriptLink" Sequence="11"> </CustomAction>
Final looks like this:
Right click the project and package it up.
Common PowerShell commands to work with solutions are (you must create the destination Document Library before you try to install this code):
To add/install Add-SPSolution H:\Path\To\wsp\Test.wsp Install-SPSolution Test.wsp -GACDeploy Update-SPSolution -literalpath H:\Path\To\wsp\Test.wsp -identity Test.wsp -GACDeploy To remove Uninstall-SPSolution Test.wsp Remove-SPSolution Test.wsp
This results in a new Feature in manage features (Active it!)
A new file in the document library, and the following in the source code for the page. Done!:
Comments are closed.