简体   繁体   中英

How do I add a css or js file to current MasterPage by wsp deploy?

Is it possible to do it?

Or do I need to deploy a new mastepage.

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"/>

You can using an "AdditionalPageHead" delegate control..

It is explained quite well here

Grab the SmartTools.jQuerySetup zip file from the SmartTools for SharePoint project here: http://smarttools.codeplex.com/Release/ProjectReleases.aspx?ReleaseId=22111

It's a WSP that deploys a feature called jQuery which consists of the jquery file, an aspx control (that references jquery), and a feature that uses the AdditionalPageHead delegate control.

Once the feature is activated you'll have jQuery on every page in the web app without any master page modifications (including application pages).

Alex is right,

in addition, I find using wspbuilder a top addon for building wsp files.

www.codeplex.com/wspbuilder

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM