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

  • Question

  • 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.
    Saturday, November 13, 2010 4:06 AM

Answers

  • Windows Mobile devices (including emulator which is a simulated device) don't have drive letters and don't support relative paths.

    All paths are specified in full from the root folder "\".

    For example that would be a file called 'text.txt' located in the root folder:

    string path = @"\test.txt";

    Note this file would be on the emulator's simulated file system and you will not be able to find it on your desktop hard drive. Use WMDC to access the emulator's file system - just like you would do with actual device.


    This posting is provided "AS IS" with no warranties, and confers no rights.
    Saturday, November 13, 2010 6:17 AM

All replies

  • Windows Mobile devices (including emulator which is a simulated device) don't have drive letters and don't support relative paths.

    All paths are specified in full from the root folder "\".

    For example that would be a file called 'text.txt' located in the root folder:

    string path = @"\test.txt";

    Note this file would be on the emulator's simulated file system and you will not be able to find it on your desktop hard drive. Use WMDC to access the emulator's file system - just like you would do with actual device.


    This posting is provided "AS IS" with no warranties, and confers no rights.
    Saturday, November 13, 2010 6:17 AM
  • Windows Mobile devices (including emulator which is a simulated device) don't have drive letters and don't support relative paths.

    All paths are specified in full from the root folder "\".

    For example that would be a file called 'text.txt' located in the root folder:

    string path = @"\test.txt";

    Note this file would be on the emulator's simulated file system and you will not be able to find it on your desktop hard drive. Use WMDC to access the emulator's file system - just like you would do with actual device.


    This posting is provided "AS IS" with no warranties, and confers no rights.


    What is the @ in your path?

    1>.\TestRunner.cpp(19) : error C2018: unknown character '0x40'

    1>.\TestRunner.cpp(19) : warning C4129: 'W' : unrecognized character escape sequence

    1>.\TestRunner.cpp(19) : error C2065: 'L' : undeclared identifier

    1>.\TestRunner.cpp(19) : error C2143: syntax error : missing ')' before 'string'

    1>.\TestRunner.cpp(19) : error C2059: syntax error : ')'

    1>.\TestRunner.cpp(20) : error C2143: syntax error : missing ';' before '{'

    Monday, June 20, 2011 1:26 AM