Question

How do get the startup path ( system.windows.forms.application.StartupPath ) of my exe without adding a reference to system.windows.forms?

Was it helpful?

Solution

You could try

System.AppDomain.CurrentDomain.BaseDirectory

which would work for most cases.

OTHER TIPS

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

You can get the startup path without reflection by using:

IO.Path.GetDirectoryName(Diagnostics.Process.GetCurrentProcess().MainModule.FileName)
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top