I would like to get the path to the execution directory of a windows forms application (ie: the directory in which the executable is located). Does anyone know of a built-in method in .Net to do this?
+6
A:
In VB.NET
Dim directory as String = My.Application.Info.DirectoryPath
In C#
string directory = AppDomain.CurrentDomain.BaseDirectory;
Tomas Pajonk
2008-11-17 14:36:11
The C# location will also work in VB or other languages that don't support the "My" namepsace.
Joel Coehoorn
2008-11-17 14:53:08
@Tomas Pajonk, may I suggest changing the c# "FileName" variable to "directory"?
grenade
2010-04-21 09:32:49
@grenade done. Thanks.
Tomas Pajonk
2010-04-21 09:41:48
+3
A:
Application.Current results in an appdomain http://msdn.microsoft.com/en-us/library/system.appdomain_members.aspx
Application.Current.BaseDirectory should give you the location of the assembly
I seem to recall there being multiple ways of getting the location of the application. but this one worked for me in the past atleast (it's been a while since i've done winforms programming :/)
thmsn
2008-11-17 14:41:08
A:
string apppath =
(new System.IO.FileInfo
(System.Reflection.Assembly.GetExecutingAssembly().CodeBase)).DirectoryName;
MusiGenesis
2008-11-17 14:50:07
Sorry, the Assembly namespace and the code display panel do not play nicely together. I hate scrollbars.
MusiGenesis
2008-11-17 14:51:55