2007-01-30

Application startup path


I spent 2 hours searching the net to find an alternative to the Application.StartUpPath command. This property returns the path from where the application exe has been started. I didn't wanted to use this, because I was writing a Console Application and the Application.StartUpPath is located in the System.Windows.Forms namespace (System.Windows.Forms.Application.StartupPath), so the console application has no reference to it. You can use a workaround by including the System.Windows.Forms .Net reference, but there is a simple solution:
the Environment.CurrentDirectory Property.

Gets or sets the fully qualified path of the current directory; that is, the directory from which this process starts.

string dir = System.Environment.CurrentDirectory;

You're welcome!

No comments: