我是 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();
}
}
- Windows Mobile 6.x 设备上没有驱动器盘符
- 没有\users目录
忘掉针对 Windows Phone 或 Windows Embedded 8 Handheld 的答案。
关于c# - 在 C# 中为 Windows Mobile App 创建一个文本文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35912238/