Getting current directory in Windows CE 5.0 using C# compact 2.0
Asked Answered
K

3

6

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?

Knitted answered 13/12, 2012 at 6:36 Comment(0)
K
8

Problem solved by using:

System.Reflection.Assembly.GetExecutingAssembly().GetName().CodeBase;
Knitted answered 13/12, 2012 at 9:19 Comment(0)
D
4

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);
Dorise answered 24/1, 2018 at 8:49 Comment(1)
This code is perfect and worked for me to return my App directory. Thanks a bunch @FlyingFox.Decumbent
I
2

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

Inhibitory answered 13/1, 2013 at 22:27 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.