views:

31

answers:

1

I have a project called WebResources where I have all the JS files that I intend to use in 2 other projects (all three projects sit in the same solution).

I just spent 2 hours playing around with the file paths and VS just doesn't see the JS file (unless I specify the full path with the drive letter). Is there a trick to including javascript files relatively from other projects?

My file structure is something like:

Project1
  Default.aspx
Project2
WebResourcesProject
   /js
     testToInclude.js

No matter how I try to include testToInclude.js inside Default.aspx, VS doesn't see it.

Any ideas?

A: 

To include relatively a file like as an image, css or js, they should be placed in the same server.

Let's say your server root is http://localhost:8080/ , and you map each project to separate folders such as http://localhost:8080/WebResourcesProject/ and http://localhost:8080/Project1/ then you could include the js like this (from the default.aspx file):

<script type="text/javascript" src="../WebResourcesProject/js/testToInclude.js" />

You can easily try that if you deploy your projects into your local IIS. If you're using the development webserver that visual studio give us, it seems to be not that easy. If there is not any real need of having the projects separately or referencing files relatively, I would consider either merging them or making absolute references.

Matias
ya that doesn't work.
gnomixa
Why? Have you tried to access localhost:8080 without setting up your web server?
Matias
Oh I see! Sorry didn't notice the "VS webserver part" - I think you might be bang on. I will try it when I get to work tomorrow. What I am concerned with is how it's going to work on production - I guess it will be ok since it's not running using VS server.
gnomixa
it worked! thanks!
gnomixa