How to get current directory in C# for any Windows version?
Posted
by
DarthRoman
on Stack Overflow
See other posts from Stack Overflow
or by DarthRoman
Published on 2011-11-15T17:20:52Z
Indexed on
2011/11/15
17:51 UTC
Read the original article
Hit count: 238
I am creating an application that can be executed in any windows version, even in mobile's, and I am trying to get the current directory of the executable. The problem is that if I use the following code, it doesn't compile in Windows Mobile:
string currentDirectory = System.IO.Path.GetDirectoryName(System.Windows.Forms.Application.ExecutablePath);
And if I use this code, I receive something like: file:\C:\xxx
string currentDirectory = System.IO.Path.GetDirectoryName(System.Windows.Forms.Application.ExecutablePath);
Although, I need to get the root drive, and this code doesn't compile in Windows Mobile:
String rootPath = Path.GetPathRoot(Environment.SystemDirectory);
Does anyone know how to get the current directory of the application and the root path for any windows version, even mobile's?
© Stack Overflow or respective owner