How do get the startup path ( system.windows.forms.application.StartupPath ) of my exe without adding a reference to system.windows.forms?
StartupPath property returns the path for the executable file that started the application, not the path where the application executable is stored. ExecutablePath property returns the path for the executable file that started the application, including the executable name.
Where did the name of the application appear in VB net? At the top of the form there is a title bar which displays the forms title. Form1 is the default name, you can change the name to your convenience . The title bar also includes the control box, which holds the minimize, maximize, and close buttons.
You could try
System.AppDomain.CurrentDomain.BaseDirectory
which would work for most cases.
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)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With