Path of the local directory
A rather simple question; how to find the path of the local directory in which my exe is placed? As-in I have an .exe and in the program I have to create a txt file in the directory where the exe is!
[language - C#]
So, if the exe is in C:/Temp and is started from there; my txt should be created in 开发者_如何转开发C:/Temp
If the user wishes to move the exe to D:/Temp and runs from there; I should be able to create the txt file in D:/Temp
I tried the Directory.GetCurrentDirectory() but that returns the directory of the execution of the program!
Assembly.GetExecutingAssembly().Location
try this
sPath = System.AppDomain.CurrentDomain.BaseDirectory;
or else
sAppPath = Environment.CurrentDirectory;
A similar information is in System.Appdomain.BaseDirectory
, the base directory that the assembly resolver uses to probe for assemblies.
In simple cases, this will point to the location of the original .exe
assembly.
String path = AppDomain.CurrentDomain.BaseDirectory;
You could try this:
this.GetType().Assembly.CodeBase
or if it's a WinForms app
Application.ExecutablePath
You can use Application.StartupPath. It Gets the path for the executable file that started the application, not including the executable name.
精彩评论