getting file Name

Discussion in 'ASP General' started by Laurent, Jul 5, 2004.

  1. Laurent

    Laurent Guest

    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
     
    Laurent, Jul 5, 2004
    #1
    1. Advertising

  2. Laurent

    Ray at Guest

    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" <> wrote in message
    news:40e9b975$0$16301$...
    > 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, Jul 5, 2004
    #2
    1. Advertising

  3. Laurent wrote:
    >
    > 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.


    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.
     
    Dave Anderson, Jul 5, 2004
    #3
  4. Laurent

    Bob Lehmann Guest

    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" <> wrote in message
    news:%...
    > Laurent wrote:
    > >
    > > 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.

    >
    > 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, Jul 6, 2004
    #4
  5. Bob Lehmann wrote:
    > WOW! And to think it could have been done in only 3 lines instead.


    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.



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


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


    >> 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.
     
    Dave Anderson, Jul 6, 2004
    #5
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. =?iso-8859-1?B?bW9vcJk=?=
    Replies:
    7
    Views:
    831
    Roedy Green
    Jan 2, 2006
  2. ding feng
    Replies:
    2
    Views:
    2,824
    ding feng
    Jun 25, 2003
  3. Bobby Chamness
    Replies:
    2
    Views:
    2,401
    Joe Smith
    Apr 22, 2007
  4. Jack-2
    Replies:
    3
    Views:
    273
    Jack-2
    Dec 24, 2003
  5. Java  script  Dude

    IE name="name" & form.name property bug

    Java script Dude, Jun 29, 2004, in forum: Javascript
    Replies:
    5
    Views:
    248
    Java script Dude
    Jun 30, 2004
Loading...

Share This Page