Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Current Page/File Name 1

Status
Not open for further replies.

OrWolf

MIS
Mar 19, 2001
291
What syntax would I use to set a variable equal to the current page/file name?
 
or

Request.ServerVariables("Script_Name") -Ovatvvon :-Q
 
OrWolf...

You don't need to set a variable equal to the current page/file name, as it is automatically done for you in what is known as 'Server Variables'.

There are a whole list of server variables, the two mentioned in above posts PATH_INFO and SCRIPT_NAME will both give you path and file names. ie They both return values in the form c:\mypath\myscript.asp

You use them in code with the syntax:
Request.ServerVariables("PATH_INFO")

Therefore,

Response.Write Request.ServerVariables("PATH_INFO")

would write the current path and filename on your HTML page.


The server variables are read only, so you can only use them in the above manner. Brett Birkett B.Comp
Systems Analyst
 
Brett,
you're slightly incorrect. Script_Name will not return the path info on the file structure (ie: c:\mypath\...). It will return in url format based on the value. If the url was
then it would return

aFolder/anotherOne/test.asp


If you want to get the server file structure (ie: c:\inetpub\ then the code would be

response.write server.mapPath("test.asp")


hope this helps... :) -Ovatvvon :-Q
 
Your right Ovatvvon! Thanks! And so does PATH_INFO, same format. Another note is that the path begins at the IIS virtual root directory.

Brett Birkett B.Comp
Systems Analyst
 
Is there any way to retrieve just the file name?
 
Yes...it's a little more complex though (not too bad though) and would probably work better if you put it into a function, but here's how you'd do it...

split it into an array seperated by the slashes "/"...then take the most upper bound object in the array...and that's your file name...here's how it'd look...

<%
Dim path, i
path = request.serverVariables(&quot;script_name&quot;)
path = split(path,&quot;/&quot;)
i = UBOUND(path)

Response.write(path(i))
%>

That will write the actual file/page name to the screen including the file extension (ex: &quot;page.asp&quot; instead of just &quot;page&quot;)

Hope this helps! -Ovatvvon :-Q
 
Thanks for the help. That last example was exactly what I was looking for, and it worked great.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top