How to Write/Read a Text File in windows mobile emulator?

Discussion in 'Windows Phone Apps and Games' started by ajoysaha, Nov 12, 2010.

  1. ajoysaha

    ajoysaha New Member

    Joined:
    Nov 12, 2010
    Messages:
    1
    Likes Received:
    0
    i'm using VS 2008. my code are given here..

    string path = @"c:\\test.txt";
    if (!File.Exists(path))
    {
    using (StreamWriter sw = File.CreateText(path))
    {
    sw.WriteLine("Hello");
    sw.WriteLine("And");
    sw.WriteLine("Welcome");
    }
    }
    using (StreamReader sr = File.OpenText(path))
    {
    string s = "";

    label1.Text="";
    while ((s = sr.ReadLine()) != null)
    {
    label1.Text+=s;
    }
    }

    but error message: Could not find a part of the path '\c:\test.txt'.

    Though i am using many code from Internet but still i can not write a file and read from this file.I want to create a file if not exists and want to write and read text from that file but problem is that path not found.So please help to do that.
  2. Marios Karagiannis

    Marios Karagiannis New Member

    Joined:
    Dec 1, 2010
    Messages:
    4
    Likes Received:
    0
    From the top of my head, I think you problem is that you didn't close the file after writing to it and before opening it again for reading. So I am guessing the file never got created in the first place (hence the error). Did you try manually creating one?
    Also, for Windows Phone 7 you might want to take a look at Isolated Storage, because this is the only way the phone allows file manipulation.

Share This Page