R – How to add a css or js file to current MasterPage by wsp deploy

sharepointwspbuilder

Is it possible to do it?

Or do I need to deploy a new mastepage.

Best Answer

If you're writing the manifest.xml file yourself, use the TemplateFiles element for CSS and JS files. For example:

<TemplateFiles>
  <TemplateFile Location="LAYOUTS\Custom\Company.css" /> 
</TemplateFiles>

However, the easiest way to do it is by using a tool that manages creation of the WSP file for you.

When using WSPBuilder, files under the 12 folder in the WSPBuilder project are automatically placed on the file system in the corresponding location. For example, 12\TEMPLATE\LAYOUTS\Custom\Company.css would be automatically deployed to "%CommonProgramFiles%\Microsoft Shared\web server extensions\12\TEMPLATE\LAYOUTS\Custom\Company.css".


To reference the CSS and/or JavaScript from a master page, use _layouts for the file path. This maps to "%CommonProgramFiles%\Microsoft Shared\web server extensions\12\TEMPLATE\LAYOUTS" on the file system.

Based on the example above:

<link rel="stylesheet" type="text/css" href="/_layouts/Custom/Company.css"/>