2
private void button1_Click(object sender, EventArgs e)
    {
        string fileLoc = @"c:\wms.txt";

        if (File.Exists(fileLoc))
        {
            using (TextReader tr = new StreamReader(fileLoc))
            {
                MessageBox.Show(tr.ReadLine());
            }
        }
    }

This works perfectly in when I create a Windows Application.

When I use the same code in a Device application - Windows CE i get error:

enter image description here

Using: .Net 2.0 , visual Studio 2005

lgaud
  • 2,430
  • 20
  • 30
Werner van den Heever
  • 745
  • 6
  • 17
  • 40

3 Answers3

5

Your device does not have a c drive. Replace

string fileLoc = @"c:\wms.txt";

with

string fileLoc = @"wms.txt";

It seems that the root folder is automatically added to your path with a \

juergen d
  • 201,996
  • 37
  • 293
  • 362
  • 1
    Wouldn't you want the "\" still left in there, or else you will get a relative location? – gunr2171 Sep 30 '13 at 13:55
  • 1
    @gunr2171 As far as I remember, Windows CE does not have a concept of "current directory" either, so all paths are automatically assumed to start at root, which means that `\\` is really optional. – Andrei Sep 30 '13 at 15:10
3

Windows CE does not have a concept of drive letters. Your path there should simply be @"\wms.txt".

Andrei
  • 1,015
  • 1
  • 11
  • 19
-1

try

string fileLoc = @"c:\wms.txt";

or

string fileLoc = "c:\\wms.txt";
Mr.LamYahoo
  • 1,536
  • 13
  • 28
  • 1
    Your first example is exactly what the OP tried, and the second is just another way to escape a backslash. – gunr2171 Sep 30 '13 at 15:13