Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Creating a file in Windows CE 5.0 in C#

I'm using a Windows CE 5.0 mobile device, Visual Studio 2008 and Compact Framework 2.0

When I execute the application trough VS 2008, the program it's copied into a folder inside the Windows CE 5.0 device and it's shown in its display. I want to create a text file there.

Here is the code I'm trying:

try
{
  TextWriter tw = new StreamWriter("date.txt");

  // write a line of text to the file
  tw.WriteLine(DateTime.Now);

  // close the stream
  tw.Close();
  label1.Text = "file created";
}
catch (Exception ex)
{
  label1.Text = ex.Message;
}

There is no error message, but the file is not created, neither in my computer (where the project is) nor in the Windows CE 5.0 terminal device (where the program is automatically copied each time is debugging).

Any idea what am I doing wrong?

like image 538
rfc1484 Avatar asked Jan 22 '26 09:01

rfc1484


1 Answers

private void saveFile()
{
    // If the File does not exist, create it!

    if (! File.Exists("date.txt") ) // may have to specify path here!
    {
        // may have to specify path here!
        File.Create("date.txt").Close();
    }

    // may have to specify path here!
    StreamWriter swFile =
                 new StreamWriter(
                    new FileStream("date.txt",
                                   FileMode.Truncate),
                    Encoding.ASCII);

    swFile.Write("some text");

    swFile.Close();

}