0

I'm doing my very first Visual Web Part in SharePoint 2010 Server, my question is easy i guess but couldn't find the right answer yet, I want to attach my resources files (JS and CSS) using the old way of web development
e.g.:

<script type="text/javascript" src="/_layouts/AnnouncementWebPart/js/jquery-1.6.1.min.js" />

I added my JS files to the Layout mapping folder Layout-->MyWebPartName-->JSFolder
I did the same for the CSS and then I included them all in the ascx page but nothing really happened when I deployed it to the SharePoint Site!

Whats wrong? i dont want to use the SharePoint Tag for including SharePoint:ScriptLink, is there any chances to do that?

3
  • I'm quite new to SharePoint myself but I've done what you're asking. If you browse to this script in a web browser, yourSharePointSite/_layouts/AnnouncementWebPart/js/…, does it load up or give a HTTP 404? Stupid question, but is this the correct path in the _layouts folder? Commented Nov 16, 2011 at 16:42
  • @nickyt: Yes its valid path as far as i know you can set resources in custom path like I did, and yes its loaded actually C:\Program Files\Common Files\Microsoft Shared\Web Server Extensions\14\TEMPLATE\LAYOUTS\AnnouncementWebPart\js\jquery-1.6.1.min Commented Nov 17, 2011 at 4:35
  • SharePoint related questions would be very welcome on sharepoint.stackexchange.com - you might want to consider posting it there, or better still asking for it to be migrated. Commented Nov 20, 2011 at 10:27

2 Answers 2

1

In my case it works both using the script tag or the SharePoint:ScriptLink tag. You can try to explicitly close the script tag (self-closed can not be supported in some browsers):

<script type="text/javascript" src="/_layouts/AnnouncementWebPart/js/jquery-1.6.1.min.js" ></script>

or you can check from Visual Studio, in the properties of JS files, that the “Build Action” is “Content” and “Deployment Type” is “TemplateFile” (see at the end of this post).

Sign up to request clarification or add additional context in comments.

Comments

0

when you set up your SharePoint VS.NET project, did you set it to deploy as Farm? From what I know, the stuff in the layouts folder will be available to all site collections if you deploy to the farm. It's an option when you're setting up where to deploy when you create your SP VS.NET project.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.