SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

What is the proper way (i.e. without having to manually copy the assets to any sharepoint folder or anything like that) to add custom javascript and CSS to a SP 2010 web part?

I would like them to be a part of the solution so that I don't have to deploy the solution and remember to copy/remove files anywhere.

Edit: If possible, please describe how to do that both in sandbox and non-sandbox solutions.

share|improve this question

If you're deploying the web part as part of a .wsp deploy the files to a mapped folder like _layouts as part of the solution. Just right click on the project in Visual Studio and click Add > SharePoint "Layouts" Mapped Folder. Then put the files you need in that folder and they'll be deployed during the solution install.

share|improve this answer
Then you can reference them with a relative url, eg: "_layouts/myscript.js" – RJ Cuthbertson Jun 13 '12 at 18:24
Does this mean it cannot be a sandbox solution? If yes, is there a way to achieve this in a sandbox solution? – andersonvom Jun 13 '12 at 18:45… according to this, not via this method. – RJ Cuthbertson Jun 13 '12 at 18:52

Just use modules to add your assets (css and javascript). The best way to learn how to do, read Thomas Balkeståhl's blog.

enter image description here

And download his Visual Studio template and create your solution from his template.

share|improve this answer

For non-sandbox solution you can add JS and CSS files in the Layout mapped folder then use the SharePoint:ScriptLink tag for javascript files:

<SharePoint:ScriptLink id="ScriptLink1" runat="server" Localizable="false" Name="projectname/some-js-file.js" />

where the path projectname/some-js-file.js is inside the Layout folder.

For css files use the SharePoint:CssRegistration tag instead:

<SharePoint:CssRegistration ID="CssRegistration1" runat="server" Name="/_layouts/projectname/some-css-file.css" />

See here for more details:

share|improve this answer

You can add Javascript using sandbox soltuion to one of your libraries. I have recently add JQuery library. Here are the steps from my blog post

share|improve this answer
Since your blog post is just a few lines please just paste your content here and add a link to your blog for reference if it adds value. That way the content is here to help visitors, whereas links go stale. And you'll probably get upvotes instead of downvotes ;-) – SPDoctor Feb 1 '13 at 21:50

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.