[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,
Re: [02/03] Obtaining the current directory
Hi
From the help (translated by me :rolleyes: )
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 :wave:
Re: [02/03] Obtaining the current directory
Environment.CurrentDirectory is the only one that is not read only. It can be assigned a value.
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.
Re: [02/03] Obtaining the current directory
Ok thanks for all the help :)
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.
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