开发者

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?


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();

}


TextWriter twFile = new StreamWriter (StockFileLoc);
twFile.Write (sbStock.ToString ());
twFile.Flush ();
twFile.Close ();

I use StringBuilder to create file, but a regular string will suffice, StockFileLoc contains the file location

StockFileLoc = @"\folder\file.txt";
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜