2

Possible Duplicate:
How can I get the application's path in .NET in a console app?

Hi,

I would like to find the absolute path from where my exe file is running.

i.e if i run my application/exe from c:\my-app\myapp.exe then it should return c:\my-app.

My target is to find my database location inside the db folder.

Community
  • 1
  • 1
KoolKabin
  • 17,157
  • 35
  • 107
  • 145

1 Answers1

2

System.Reflection.Assembly.GetExecutingAssembly().GetName().CodeBase gives you the name of the exe, and System.IO.Path.GetDirectoryName(...) then pulls the directory part out.

See http://msdn.microsoft.com/en-us/library/aa457089.aspx#howtoexecutingapppath_topic2

AAT
  • 3,286
  • 1
  • 22
  • 26