wusher
wusher

Reputation: 12451

Get the startup path in a vb.net console exe

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

Upvotes: 5

Views: 38425

Answers (3)

Mitch Wheat
Mitch Wheat

Reputation: 300769

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

Upvotes: 4

JamesSugrue
JamesSugrue

Reputation: 15011

You could try

System.AppDomain.CurrentDomain.BaseDirectory

which would work for most cases.

Upvotes: 20

Andrew Moore
Andrew Moore

Reputation: 95444

You can get the startup path without reflection by using:

IO.Path.GetDirectoryName(Diagnostics.Process.GetCurrentProcess().MainModule.FileName)

Upvotes: 3

Related Questions