Connecting Tech Pros Worldwide Forums | Help | Site Map

getting file Name

Laurent
Guest
 
Posts: n/a
#1: Jul 19 '05
Hi all,

I'm searching to find the name of the file in which i execute a script.

example : i'm into /directory/page.asp

and i d like to know which variable could help me to find the path of the
file on server side.

thanks a lot and have a nice day


Laurent
http://www.chazallet.com



Ray at
Guest
 
Posts: n/a
#2: Jul 19 '05

re: getting file Name


Make a page like this:

<%
For Each q in Request.ServerVariables
Response.Write q & " = " & Request.ServerVariables(q) & "<hr>"
Next
%>

That'll show you all the server variables.

Also see this: http://www.aspfaq.com/show.asp?id=2072

Ray at home

"Laurent" <lgoffin@wonderweb.net> wrote in message
news:40e9b975$0$16301$a0ced6e1@news.skynet.be...[color=blue]
> Hi all,
>
> I'm searching to find the name of the file in which i execute a script.
>
> example : i'm into /directory/page.asp
>
> and i d like to know which variable could help me to find the path of the
> file on server side.
>
> thanks a lot and have a nice day
>
>
> Laurent
> http://www.chazallet.com
>
>[/color]


Dave Anderson
Guest
 
Posts: n/a
#3: Jul 19 '05

re: getting file Name


Laurent wrote:[color=blue]
>
> I'm searching to find the name of the file in which i execute a
> script.
>
> example : i'm into /directory/page.asp
>
> and i d like to know which variable could help me to find the
> path of the file on server side.[/color]

Here's one JScript way of doing it:

function showServerVariables() {
var v = Request.ServerVariables
e = new Enumerator(v),
a = new Array(),
s = new String()
for (; !e.atEnd(); e.moveNext()) {
s = String(e.item())
if (!/^ALL/.test(s))
a.push(
"<TD><B>" + s + "</B></TD>" +
"<TD>" + split(v(s)) + "</TD>"
)
}

return "<TABLE><TR VALIGN=\"top\">" +
a.join("</TR>\r\n<TR VALIGN=\"top\">") +
"</TR>\r\n</TABLE>"

function split(item) {
item = String(item)
return item.replace(
/([;\n])/g,"$1<BR>"
).replace(
/(,)/g,"$1 "
).replace(
/(&)/g,"&<BR>&nbsp;&nbsp;&nbsp;"
)
}
}

<%=showServerVariables()%>


--
Dave Anderson

Unsolicited commercial email will be read at a cost of $500 per message. Use
of this email address implies consent to these terms. Please do not contact
me directly or ask me to contact you directly for assistance. If your
question is worth asking, it's worth posting.


Bob Lehmann
Guest
 
Posts: n/a
#4: Jul 19 '05

re: getting file Name


WOW! And to think it could have been done in only 3 lines instead.

Nice job.

Bob Lehmann
Verbose, overly-complex code will be read at a cost of $500 per line.

"Dave Anderson" <GTSPXOESSGOQ@spammotel.com> wrote in message
news:%2322dqntYEHA.556@tk2msftngp13.phx.gbl...[color=blue]
> Laurent wrote:[color=green]
> >
> > I'm searching to find the name of the file in which i execute a
> > script.
> >
> > example : i'm into /directory/page.asp
> >
> > and i d like to know which variable could help me to find the
> > path of the file on server side.[/color]
>
> Here's one JScript way of doing it:
>
> function showServerVariables() {
> var v = Request.ServerVariables
> e = new Enumerator(v),
> a = new Array(),
> s = new String()
> for (; !e.atEnd(); e.moveNext()) {
> s = String(e.item())
> if (!/^ALL/.test(s))
> a.push(
> "<TD><B>" + s + "</B></TD>" +
> "<TD>" + split(v(s)) + "</TD>"
> )
> }
>
> return "<TABLE><TR VALIGN=\"top\">" +
> a.join("</TR>\r\n<TR VALIGN=\"top\">") +
> "</TR>\r\n</TABLE>"
>
> function split(item) {
> item = String(item)
> return item.replace(
> /([;\n])/g,"$1<BR>"
> ).replace(
> /(,)/g,"$1 "
> ).replace(
> /(&)/g,"&<BR>&nbsp;&nbsp;&nbsp;"
> )
> }
> }
>
> <%=showServerVariables()%>
>
>
> --
> Dave Anderson
>
> Unsolicited commercial email will be read at a cost of $500 per message.[/color]
Use[color=blue]
> of this email address implies consent to these terms. Please do not[/color]
contact[color=blue]
> me directly or ask me to contact you directly for assistance. If your
> question is worth asking, it's worth posting.
>
>[/color]


Dave Anderson
Guest
 
Posts: n/a
#5: Jul 19 '05

re: getting file Name


Bob Lehmann wrote:[color=blue]
> WOW! And to think it could have been done in only 3 lines instead.[/color]

Or two:
for (var v=Request.ServerVariables,e=new
Enumerator(v),a=[],s="";!e.atEnd();e.moveNext()){s=String(e.item()); a.push("
["+s+"] "+v(s))}
<%=a.join("<BR>")%>

Why not one?
<%=Request.ServerVariables%>



Of course, neither of these breaks out the cookies and their keyed
name/value pairs into separate line items as my posted example does.

But I suppose you think an example must be written anew each time a question
is to be answered, rather than lifted from any utility scripts we may have
lying around. I confess I am not fond of leaving markup in my examples, but
I considered it relevant in this case.


[color=blue]
> Nice job.
>
> Bob Lehmann
> Verbose, overly-complex code will be read at a cost of $500 per line.[/color]

Whatever. If push/join/replace is complex, then sue me.

[color=blue][color=green]
>> function showServerVariables() {
>> var v = Request.ServerVariables,
>> e = new Enumerator(v),
>> a = new Array(),
>> s = new String()
>> for (; !e.atEnd(); e.moveNext()) {
>> s = String(e.item())
>> if (!/^ALL/.test(s))
>> a.push(
>> "<TD><B>" + s + "</B></TD>" +
>> "<TD>" + split(v(s)) + "</TD>"
>> )
>> }
>>
>> return "<TABLE><TR VALIGN=\"top\">" +
>> a.join("</TR>\r\n<TR VALIGN=\"top\">") +
>> "</TR>\r\n</TABLE>"
>>
>> function split(item) {
>> item = String(item)
>> return item.replace(
>> /([;\n])/g,"$1<BR>"
>> ).replace(
>> /(,)/g,"$1 "
>> ).replace(
>> /(&)/g,"&<BR>&nbsp;&nbsp;&nbsp;"
>> )
>> }
>> }
>>
>> <%=showServerVariables()%>[/color][/color]


--
Dave Anderson

Unsolicited commercial email will be read at a cost of $500 per message. Use
of this email address implies consent to these terms. Please do not contact
me directly or ask me to contact you directly for assistance. If your
question is worth asking, it's worth posting.


Closed Thread