c# - 在 C# 中为 Windows Mobile App 创建一个文本文件

标签 c# windows-mobile

我是 C# 的新手,目前正在开发一个 Windows 移动应用程序,我必须在其中创建一个按钮单击事件的文本文件,并且必须写入页面中存在的文本字段的值。任何人都可以帮助我吗为此,我为此使用了 Visual 2008。

private void btnSubmit_Click(object sender, EventArgs e)
{
    string path = "C:\\Users\\Mytext.txt";

    if (!File.Exists(path))
    {
        File.Create(path);
        TextWriter tw = new StreamWriter(path);
        tw.WriteLine("The very first line!");
        tw.Close();
    }
    else if (File.Exists(path))
    {
        TextWriter tw = new StreamWriter(path);
        tw.WriteLine("The next line!");
        tw.Close();
    }
}

最佳答案

用那个

private void btnSubmit_Click(object sender, EventArgs e)
{
  string path = "\\My Documents\\Mytext.txt";

  if (!File.Exists(path))
  {
    File.Create(path);
    TextWriter tw = new StreamWriter(path);
    tw.WriteLine("The very first line!");
    tw.Close();
  }
  else if (File.Exists(path))
  {
    TextWriter tw = new StreamWriter(path);
    tw.WriteLine("The next line!");
    tw.Close();
  }
}
  1. Windows Mobile 6.x 设备上没有驱动器盘符
  2. 没有\users目录

忘掉针对 Windows Phone 或 Windows Embedded 8 Handheld 的答案。

关于c# - 在 C# 中为 Windows Mobile App 创建一个文本文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35912238/

相关文章:

c# - WCF:为不同的操作设置不同的超时

c# - 具有缓存和 SqlMethods 的存储库模式

C# Windows 窗体应用程序 - 从另一个线程和类更新 GUI?

api - 哪些设备制造商拥有自己的 Java ME API

c# - Windows Mobile (C#) - 手机和 PC 之间的通信

C# 语法 lambda 带大括号

android - Android 工业手持终端?

c# - 重定向到设备设置

javascript - 媒体查询不适用于移动 IE

c# - 一个按钮执行两个命令