Question

How do I get the current directory from which my EXE is running? I have tried the following two codes but they don't work.

Path.GetDirectoryName(Assembly.GetExecutingAssembly().GetName().CodeBase);

Using above I get error "The name "Assembly" does not exist..."

Directory.GetCurrentDirectory()

also doesn't work.

EDIT
Ok I found another code that works but it is giving me directory "\Windows" but my program is running from an SD Card. I copied the program to "Program Files" folder on device but it again gave me directory "\Windows".

How do I get the current directory or more specifically how do I get SD Card/Flash Memory path?

Was it helpful?

Solution

Problem solved by using:

System.Reflection.Assembly.GetExecutingAssembly().GetName().CodeBase;

OTHER TIPS

The following code works for me to get the directory where myApp.exe has been started from on a CE 5.0 system:

// i.e. "\hard disk2\my program\myApp.exe"
string assemblyLocation = Assembly.GetExecutingAssembly().GetName().CodeBase;
// i.e. "\hard disk2\my program\"
string currentDirectory = Path.GetDirectoryName(assemblyLocation);

There is no such thing as a "current directory" on MS Windows CE, up to at least version 6.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top