How do get the startup path ( system.windows.forms.application.StartupPath ) of my exe without adding a reference to system.windows.forms?
+3
A:
EDIT: @KiwiBastard's answer is the correct method:
System.AppDomain.CurrentDomain.BaseDirectory
Add a reference to System.Reflection
and use
Assembly.GetExecutingAssembly().Location
EDIT: Depending where you intend getting the startup path, this might be more appropriate:
Assembly.GetEntryAssembly().Location
Mitch Wheat
2008-11-18 23:51:14
@KiwiBastard's answer is probably the right method...
Mitch Wheat
2008-11-19 00:17:54
+1
A:
You can get the startup path without reflection by using:
IO.Path.GetDirectoryName(Diagnostics.Process.GetCurrentProcess().MainModule.FileName)
Andrew Moore
2008-11-19 00:05:51
+4
A:
You could try
System.AppDomain.CurrentDomain.BaseDirectory
which would work for most cases.
KiwiBastard
2008-11-19 00:09:35