Results 1 to 3 of 3

Thread: Retrieve absolute file path of a file:

  1. #1

    Thread Starter
    Hyperactive Member MarkusJ_NZ's Avatar
    Join Date
    Jun 2001
    Posts
    375

    Retrieve absolute file path of a file:

    Hi, I have an Access database which I open using a connectionstring (DNS= too much hassle).

    The connection string needs to know the absolute path to the database file and the only way I can find it is by doing a bit of string manipulation.

    The example below is called by a file in a folder called admin and my database is in a folder called
    _database which is at the same level as my admin folder.

    Code:
    Dim dBaseLocation As String
    
    ' Get the absolute path to the Admin folder then replace the Admin folder with an empty string. Also concatenate the _database folder and database name to give me the absolute path to the folder.
    
    dBaseLocation = Replace(Server.MapPath(""), "Admin", "") 
    & "\_database\databasestore_be.mdb"
    
    ' Just in case
    dBaseLocation = Replace(dBaseLocation, "\\", "\")
    This code works fine but it seems a little longwinded.

    I see that the system.IO space includes a Path class. I tried a few of the methods of this class but never achieved what the above bit of spaghetti code did.

    Does anyone have a better way of doing the above?

    Cheers
    MarkusJ

  2. #2
    Addicted Member
    Join Date
    Jul 1999
    Posts
    207
    why wouldn't you do just this?

    Dim dBaseLocation As String

    dBaseLocation = Server.MapPath("/YourVirtualDir/Admin/_database/databasestore_be.mdb")

    Jeremy

  3. #3

    Thread Starter
    Hyperactive Member MarkusJ_NZ's Avatar
    Join Date
    Jun 2001
    Posts
    375
    Looks good

Posting Permissions

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



Click Here to Expand Forum to Full Width