Reputation: 436
Sorry if this question is answered somewhere else but I tried searching several pages and was unsuccessful.
So i have an include file (sidebar) which i am using in all pages.
Default.asp
Products.asp
Salary/Survey.asp
inc/sidebar.asp (this is the included file)
now inside sidebar.asp
I have a link for Salary/Survey.asp
from all other pages at root level, i can simply use href='Salary/Survey.asp'
and will work fine. but when I am on page Survey.asp
, writing href='Salary/Survey.asp'
will become actually Salary/Salary/Survey.asp
. I understand it has to be ../Salary/Survey.asp
to be used properly but it will then not work for root level pages.
I can not use root relative
which is /Default.asp
and /Salary/Survey.asp
as I am working for someone else' project and i dont know his directory structure and thus i only have option to document relative
path.
Hope this is clear to understand and someone helps me out.
Thanks!
Upvotes: 0
Views: 5026
Reputation: 1708
you need to get write this after the that - Salary/Survey.asp
You can get the virtual path to the file from one of several server variables - try either:
Request.ServerVariables("PATH_INFO")
Request.ServerVariables("SCRIPT_NAME")
Either server variable will give you the virtual path including any sub-directories and the file name - given your example, you'll get /virtual_directory/subdirectory/file.asp
. If you just want the virtual directory, you'll need to strip off everything after the second forward slash using whatever method you prefer for plucking a directory out of a path, such as:
s = Request.ServerVariables("SCRIPT_NAME")
i = InStr(2, s, "/")
If i > 0 Then
s = Left(s, i - 1)
End If
or:
s = "/" & Split(Request.ServerVariables("SCRIPT_NAME"), "/")(1)
Upvotes: 1
Reputation: 5184
We solved this problem the following way...
for example:
Then it was a matter of prefacing all the links requiring a relative path with <%=strRelativePath%>
Upvotes: 2
Reputation: 4183
basically, if your sidebar can be included from programs in different folders, the only 'easy' way is to use absolute paths like you mentioned.
You say can't use it, so I would think of different ways...
Upvotes: 0