0

I have a file stored in the same dir as my application. I try to load that file but I get an error (not found)

StreamReader str = new StreamReader("list.txt");

so, what path to the file I must declare to read it ?

Paul R
  • 208,748
  • 37
  • 389
  • 560
Tony
  • 12,405
  • 36
  • 126
  • 226

3 Answers3

5

Windows CE doesn't have the concept of "current directory". The OS tries to open \list.txt when passing "list.txt". You always have to specify the full path to the file.

3

In full framework I use:

string dir = Path.GetDirectory(Assembly.GetExecutingAssembly().Location);
string filename = Path.Combine(dir, "list.txt");
StreamReader str = new StreamReader(filename);

I don't know if in compact-framework this works, I cannot try now, sorry...

Marco
  • 56,740
  • 14
  • 129
  • 152
0

For the Compact Framework you can get the executing assembly location by using the code base path as follows:

string dir = Path.GetDirectoryName(Assembly.GetExecutingAssembly().GetName().CodeBase);
string filename = Path.Combine(dir, "list.txt");
StreamReader str = new StreamReader(filename);
sharky101
  • 812
  • 5
  • 11