Finding the 'root' level?

Discussion in 'ASP General' started by Robb Meade, Jul 2, 2003.

  1. Robb Meade

    Robb Meade Guest

    Hi all,

    I've written a small form handler script which should work for 'all' (term
    used loosely) forms...

    It will email the company, send courtesy emails to the form filler and save
    data to a text file - all with various options made easy by changing hidden
    tags in the form.

    One minor problem I've come across is that I need to be able to write to a
    specific directory on the server.

    So lets say I allow a hidden tag for the owner of the server to enter the
    name of the directory they want to write to, lets call it 'data'.

    When I use the Server.Mappath('data') in this scenario, it looks within the
    same directory, as a result it does not find the directory, and then my
    script creates one.

    The actualy directory (in the current case) is say one level above (../
    etc), but I dont know that that is always going to be the case.

    I'd rather not have to put the script in the root level of the web for this
    to always work, as for frontpage users for example they may have subwebs and
    so on, but the data folder could well be in the main root directory.

    So, how can I ensure that using the Server.Mappath('data') find the 'data'
    folder at the root level.

    I appreciate on my setup here I could simply enter the full path, ie,
    E:\webs\webdev\some-client\data but I need 'joe public' to be able to enter
    just the name of the directory (or use the default of 'form-data' or
    something), and have it written to the correct place.

    Anybody got any ideas/suggestions?

    Thanks in advance for any help,

    Regards

    Robb Meade
    Robb Meade, Jul 2, 2003
    #1
    1. Advertising

  2. Have you tried something like this:

    set fso = server.createobject("Scripting.FileSystemObject")
    if fso.folderExists(server.mappath("/") & "data") then
    ' folder exists in root!
    end if
    set fso = nothing


    Not sure if it needs to be "\data" -- I always forget the behavior of
    server.mappath. I could have tested it in the time it took me to state
    that, but I'm lazy today...




    "Robb Meade" <> wrote in message
    news:NZEMa.1322$...
    > Hi all,
    >
    > I've written a small form handler script which should work for 'all' (term
    > used loosely) forms...
    >
    > It will email the company, send courtesy emails to the form filler and

    save
    > data to a text file - all with various options made easy by changing

    hidden
    > tags in the form.
    >
    > One minor problem I've come across is that I need to be able to write to a
    > specific directory on the server.
    >
    > So lets say I allow a hidden tag for the owner of the server to enter the
    > name of the directory they want to write to, lets call it 'data'.
    >
    > When I use the Server.Mappath('data') in this scenario, it looks within

    the
    > same directory, as a result it does not find the directory, and then my
    > script creates one.
    >
    > The actualy directory (in the current case) is say one level above (../
    > etc), but I dont know that that is always going to be the case.
    >
    > I'd rather not have to put the script in the root level of the web for

    this
    > to always work, as for frontpage users for example they may have subwebs

    and
    > so on, but the data folder could well be in the main root directory.
    >
    > So, how can I ensure that using the Server.Mappath('data') find the 'data'
    > folder at the root level.
    >
    > I appreciate on my setup here I could simply enter the full path, ie,
    > E:\webs\webdev\some-client\data but I need 'joe public' to be able to

    enter
    > just the name of the directory (or use the default of 'form-data' or
    > something), and have it written to the correct place.
    >
    > Anybody got any ideas/suggestions?
    >
    > Thanks in advance for any help,
    >
    > Regards
    >
    > Robb Meade
    >
    >
    Aaron Bertrand - MVP, Jul 2, 2003
    #2
    1. Advertising

  3. Robb Meade

    Tom B Guest

    Doesn't Server.MapPath("\Data\File.txt") return relative to the root?
    What happens if your users enter the same name? Say "Data"?





    "Robb Meade" <> wrote in message
    news:NZEMa.1322$...
    > Hi all,
    >
    > I've written a small form handler script which should work for 'all' (term
    > used loosely) forms...
    >
    > It will email the company, send courtesy emails to the form filler and

    save
    > data to a text file - all with various options made easy by changing

    hidden
    > tags in the form.
    >
    > One minor problem I've come across is that I need to be able to write to a
    > specific directory on the server.
    >
    > So lets say I allow a hidden tag for the owner of the server to enter the
    > name of the directory they want to write to, lets call it 'data'.
    >
    > When I use the Server.Mappath('data') in this scenario, it looks within

    the
    > same directory, as a result it does not find the directory, and then my
    > script creates one.
    >
    > The actualy directory (in the current case) is say one level above (../
    > etc), but I dont know that that is always going to be the case.
    >
    > I'd rather not have to put the script in the root level of the web for

    this
    > to always work, as for frontpage users for example they may have subwebs

    and
    > so on, but the data folder could well be in the main root directory.
    >
    > So, how can I ensure that using the Server.Mappath('data') find the 'data'
    > folder at the root level.
    >
    > I appreciate on my setup here I could simply enter the full path, ie,
    > E:\webs\webdev\some-client\data but I need 'joe public' to be able to

    enter
    > just the name of the directory (or use the default of 'form-data' or
    > something), and have it written to the correct place.
    >
    > Anybody got any ideas/suggestions?
    >
    > Thanks in advance for any help,
    >
    > Regards
    >
    > Robb Meade
    >
    >
    Tom B, Jul 2, 2003
    #3
    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. Replies:
    0
    Views:
    1,202
  2. jm
    Replies:
    1
    Views:
    7,185
  3. Rick Osborn
    Replies:
    10
    Views:
    3,942
    Jon A. Cruz
    Feb 8, 2004
  4. pabbu
    Replies:
    8
    Views:
    708
    Marc Boyer
    Nov 7, 2005
  5. hector
    Replies:
    5
    Views:
    398
    CBFalconer
    Dec 5, 2006
Loading...

Share This Page