Search code examples
c#.net-2.0windows-cestreamreadertextreader

Read text file C#


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


Solution

  • 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 \