Results 1 to 7 of 7

Thread: [RESOLVED] [02/03] Obtaining the current directory

  1. #1

    Thread Starter
    New Member
    Join Date
    Sep 2006
    Posts
    9

    Resolved [RESOLVED] [02/03] Obtaining the current directory

    What are the differences between the following methods for obtaining the current directory:-

    -Application.StartupPath
    -Environment.CurrentDirectory
    -AppDomain.CurrentDomain.BaseDirectory

    Are there any advantages to each? Does the application you are developing (win form, service, dll etc) dictate the method that should be used?

    Regards,

  2. #2
    Hyperactive Member josep's Avatar
    Join Date
    Sep 2006
    Location
    Barcelona
    Posts
    409

    Re: [02/03] Obtaining the current directory

    Hi

    From the help (translated by me )

    StartupPath: Returns the path for the exe file that starts the applicacion.

    CurentDirectory: Returns and Sets the full parh for the curent directory, thats the directory from which this process starts

    CurrentDomain.BaseDirectory: Returns the base directory that the Assemble interpreter had use to search assemblies.

    So there are some diferences between them and you should use the one that you need. (Commonly you will use startupPath to konw where is your exe and try to find all the other resources you developed from there).

    Hope this helps you a little bit
    Last edited by josep; Sep 19th, 2006 at 11:00 AM.

  3. #3
    I'm about to be a PowerPoster! kleinma's Avatar
    Join Date
    Nov 2001
    Location
    NJ - USA (Near NYC)
    Posts
    23,373

    Re: [02/03] Obtaining the current directory

    Environment.CurrentDirectory is the only one that is not read only. It can be assigned a value.

  4. #4
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: [02/03] Obtaining the current directory

    Application.StartupPath and Environment.CurrentDirectory may contain the same path on many occasions but they are quite different. Application.StartupPath is the folder from which your EXE was run. It is always that path, no matter where that path may be, and it cannot be changed during a session. Environment.CurrentDirectory is the current working directory for the application. It will initially be the same as Application.StartupPath by default but it doesn't have to be. If you run an application from a shortcut and the "Start in:" field is set then that's what the initial value of Environment.CurrentDirectory will be. If you start a process using Process.Start and you set the WorkingDirectory property of its ProcessStartInfo then that's what the initial value of Environment.CurrentDirectory will be. Environment.CurrentDirectory can also be changed in many other ways, e.g. navigating to different folders in an OpenFileDialog or SaveFileDialog with its RestoreDirectory property set to False.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  5. #5

    Thread Starter
    New Member
    Join Date
    Sep 2006
    Posts
    9

    Re: [02/03] Obtaining the current directory

    Ok thanks for all the help

  6. #6
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: [02/03] Obtaining the current directory

    Don't forget to resolve your thread from the Thread Tools menu if you have a satisfactory answer.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  7. #7
    Frenzied Member
    Join Date
    Dec 2001
    Posts
    1,331

    Re: [RESOLVED] [02/03] Obtaining the current directory

    Thanks Guys.

    Code:
    Dim path As String
                path = Application.StartupPath & "\CodeRed_1_0_0_6\" & "CodeRed.exe.config.deploy"
                fileMap.ExeConfigFilename = path
    Steve
    steve

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