SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Zealot
    Join Date
    Oct 2001
    Location
    Montreal, Canada
    Posts
    169
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    ASP question regarding the MapPath method

    Hi ASP people,

    It seems that ASP doesn't like this piece of code:

    Code:
    dim MyFile
    MyFile = Server.MapPath(variable)
    Where variable has been assign the value of a form element sent to ASP.

    Am I dreaming or the MapPath method doesn't accept string variables as parameters? Or maybe I'm not doing it right.

    If I'm not dreaming, is there a way somehow to write to a file whose filename comes from a variable (which can be done in PHP)?

    Thanks

    Mike

  2. #2
    SitePoint Enthusiast cjam4's Avatar
    Join Date
    Jul 2001
    Location
    NJ
    Posts
    42
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    That code should work.

    I am assuming that you are setting a form element in the variable.

    Like this:

    variable = Request.Form("formName")

    Also, try this:

    Response.Write myFile

    Just do this to see if you are getting the right path.

    Hope this helps!

  3. #3
    SitePoint Wizard
    Join Date
    Jan 2001
    Location
    Milton Keynes, UK
    Posts
    1,011
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    It should work ok. Just a couple of things to be aware of though:

    1) If the the variable is preceeded by either / or \ then the variable path is taken as a full virtual path otherwise the variable path is taken as a relative path to the current dir.

    2) The value returned by the Server.MapPath method is the absolute path, which'll then need to be used to open the file with the FileSystemObjects.

    Can you give us some details of the web dir. setup and the variables and file paths you're using?

  4. #4
    SitePoint Zealot
    Join Date
    Oct 2001
    Location
    Montreal, Canada
    Posts
    169
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi,

    It's working now. My problem was in the file name itself.

    To make sure that no 2 files has the same filename I was appending the current date and time to the variable taken from the form element: test as form element value and current date of 11/21/2001 5:11:25 PM makes a filenamed test 11/21/2001 5:11:25.htm. My problem was with the space, the slashes and the dots in the time. I removed the slashes and the dotes and replace the space by underscore and it's working perfectly fine.

    Thanks for you help.

    Mike


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •