469,643 Members | 2,061 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,643 developers. It's quick & easy.

Relative & absolute path question (JavaScript, mostly)

Hi.

I have files in the "Scorecard Previews" subfolder of the virtual path
of my app,
the absolute path being

C:\Data\Ordering Process\Scorecard Previews\
I have a javascript function which changes the href of an <a>
depending on some selection in a combo. If in the javascript function
I set the href like this:

hLink.href="/Scorecard Previews/"+ cbo.options[index].text +
".doc"

the <apoints to something like

http://localhost:1218/Scorecard%20Pr...corecard_1.doc

which is not correct - it should be

http://localhost:1218/Ordering%20Process/Scorecard
%20Previews/MyScorecard_1.doc

(I'm missing part of the path) - the path to the application.
If i set the href like this:

hLink.href="~/Scorecard Previews/"+ cbo.options[index].text
+ ".doc"

the <apoints to something like

http://localhost:1218/Ordering%20Process/~/Scorecard
%20Previews/MyScorecard_1.doc

which is not correct - it should be

http://localhost:1218/Ordering%20Process/Scorecard
%20Previews/MyScorecard_1.doc

(I have an extra "~" character).

How should I set the path in JavaScript ?

In VB.net (code behind) it has been very simple:

cmdOpenScorecardPreview.NavigateUrl = "~/Scorecard
Previews/" & strSelectedScorecard
Thanks a lot
Alex

Feb 9 '07 #1
2 6105
unfortunatly iis does not support the "~" path specification (which is
really a unix feature). asp.net sorta supports it. when a server side
control renders a url it translates the "~" path to the vdir path.

to do this in javascript you can use a relative path:

hLink.href="Scorecard Previews/"
+ cbo.options[index].text + ".doc"

which will work if the current page is in the basedir. if its in a
subfolder you can navigate up "../Scorecard Previews".

to a browser "/path", means server/path.

-- bruce (sqlwork.com)

Radu wrote:
Hi.

I have files in the "Scorecard Previews" subfolder of the virtual path
of my app,
the absolute path being

C:\Data\Ordering Process\Scorecard Previews\
I have a javascript function which changes the href of an <a>
depending on some selection in a combo. If in the javascript function
I set the href like this:

hLink.href="/Scorecard Previews/"+ cbo.options[index].text +
".doc"

the <apoints to something like

http://localhost:1218/Scorecard%20Pr...corecard_1.doc

which is not correct - it should be

http://localhost:1218/Ordering%20Process/Scorecard
%20Previews/MyScorecard_1.doc

(I'm missing part of the path) - the path to the application.
If i set the href like this:

hLink.href="~/Scorecard Previews/"+ cbo.options[index].text
+ ".doc"

the <apoints to something like

http://localhost:1218/Ordering%20Process/~/Scorecard
%20Previews/MyScorecard_1.doc

which is not correct - it should be

http://localhost:1218/Ordering%20Process/Scorecard
%20Previews/MyScorecard_1.doc

(I have an extra "~" character).

How should I set the path in JavaScript ?

In VB.net (code behind) it has been very simple:

cmdOpenScorecardPreview.NavigateUrl = "~/Scorecard
Previews/" & strSelectedScorecard
Thanks a lot
Alex
Feb 9 '07 #2
On Feb 9, 11:45 am, bruce barker <nos...@nospam.comwrote:
unfortunatly iis does not support the "~" path specification (which is
really a unix feature). asp.net sorta supports it. when a server side
control renders a url it translates the "~" path to the vdir path.

to do this in javascript you can use a relative path:

hLink.href="Scorecard Previews/"
+ cbo.options[index].text + ".doc"

which will work if the current page is in the basedir. if its in a
subfolder you can navigate up "../Scorecard Previews".

to a browser "/path", means server/path.

-- bruce (sqlwork.com)

Radu wrote:
Hi.
I have files in the "Scorecard Previews" subfolder of the virtual path
of my app,
the absolute path being
C:\Data\Ordering Process\Scorecard Previews\
I have a javascript function which changes the href of an <a>
depending on some selection in a combo. If in the javascript function
I set the href like this:
hLink.href="/Scorecard Previews/"+ cbo.options[index].text +
".doc"
the <apoints to something like
http://localhost:1218/Scorecard%20Pr...corecard_1.doc
which is not correct - it should be
http://localhost:1218/Ordering%20Process/Scorecard
%20Previews/MyScorecard_1.doc
(I'm missing part of the path) - the path to the application.
If i set the href like this:
hLink.href="~/Scorecard Previews/"+ cbo.options[index].text
+ ".doc"
the <apoints to something like
http://localhost:1218/Ordering%20Process/~/Scorecard
%20Previews/MyScorecard_1.doc
which is not correct - it should be
http://localhost:1218/Ordering%20Process/Scorecard
%20Previews/MyScorecard_1.doc
(I have an extra "~" character).
How should I set the path in JavaScript ?
In VB.net (code behind) it has been very simple:
cmdOpenScorecardPreview.NavigateUrl = "~/Scorecard
Previews/" & strSelectedScorecard
Thanks a lot
Alex- Hide quoted text -

- Show quoted text -
Thank you, Bruce, it worked :-))) Have a great weekend !

Feb 9 '07 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

4 posts views Thread by Joe Cybernet | last post: by
3 posts views Thread by Peter Taurins | last post: by
7 posts views Thread by Rizaan Jappie | last post: by
6 posts views Thread by openleren | last post: by
8 posts views Thread by Daniel Serrano | last post: by
8 posts views Thread by JJ | last post: by
15 posts views Thread by Lars Eighner | last post: by
reply views Thread by gheharukoh7 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.