by Abe Miessler
12. April 2011 07:31
For something so simple, this problem took me quite a while so I wanted to share how I resolved it. In my situation I wanted to add jQuery and a few jQuery plugin files to be part of my visual web part. This web part was going to be part of a wsp that would be shipped out to SharePoint environments that I had no control over, so simply including them in the master page was not an option.
Step 1:
Right click on your project file and select Add->SharePoint "Layouts" Mapped Folder
Step 2:
In side of the Layouts Mapped folder create the following file structure
YourProjectName/js
Step 3:
Add your js files to the folder you just created in your project.
Step 4:
Inside of your ascx file for you visual web part create the ScriptLink tag
<SharePoint:ScriptLink ID="ScriptLink1" runat="server" Name="YourProjectName/js/jquery.min.js" Localizable="false" LoadAfterUI="true" />
If you have jQuery plugins, place their ScriptLink tags AFTER the jQuery tag
You should now be in business. If you are havinig problems check the following directory to make sure your scripts are being deployed:
C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\14\TEMPLATE\LAYOUTS\YourProjectName\js