I'm trying to get the directory path to the Debug folder that my application is executing in, or should I say the directory path to where my currently running EXE program is running.
Now, many of you might say to do something like this
System.Reflection.Assembly.GetExecutingAssembly().Location
I can't do this. I need to to get from an alternative assembly. I don't know what assembly this will be in, so I guess it has to work globally without changing it depending on the assembly it's currently in.
I'm looking for the best way (speed & performance thought about).
This is the prefered replacement for AppDomain.CurrentDomain.BaseDirectory
in .net core (at least until the API appears for AppDomain, if it ever will).
This is the best option all round. It will give you the base directory for class libraries, including those in ASP.NET applications.
This does an interop call using the winapi GetCurrentDirectory call inside kernel32.dll, which means the launching process' folder will often be returned. Also as the MSDN documents say, it's not guaranteed to work on mobile devices.
This simply calls Directory.GetCurrentDirectory()
This would be called using
this.GetType().Assembly.Location
This returns the full path to the calling assembly, including the assembly name itself. If you are calling a separate class library, then its base directory will be returned, such “C:\\myassembly.dll” - depending obviously on which Assembly instance is being used.
This is inside the System.Windows.Forms namespace, so is typically used in window forms application only.
The same as Application.StartupPath, however this also includes the application name, such as “myapp.exe”
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.