【问题标题】:How to set path of a text file created by an visual studio 2010 application?如何设置由 Visual Studio 2010 应用程序创建的文本文件的路径?
【发布时间】:2013-04-18 09:00:26
【问题描述】:

我正在使用 C# 在 Visual Studio 2010 中创建一个应用程序,只是为了生成一个字符串,该字符串包含该应用程序运行时手动输入的数据。我已经给出了一个创建按钮来生成该文本文件。如何在保存该应用程序 exe 文件的位置创建该文本文件?它是在代码中给出的 C:\ 中生成的。

【问题讨论】:

标签: c# visual-studio-2010 file text path


【解决方案1】:

可执行文件所在的文件夹是:

string executableLocation = System.IO.Path.GetDirectoryName(
    System.Reflection.Assembly.GetExecutingAssembly().Location);

所以你想把你的文件保存到:

System.IO.Path.Combine(executableLocation, "myfile.txt");

【讨论】:

  • string executableLocation = System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location); System.IO.Path.Combine(executableLocation, "MyFile.txt"); System.IO.File.WriteAllText(?????????, MyString);我应该把什么放在这里??????将 MyString 写入该 MyFile.txt 中?
  • System.IO.Path.Combine(executableLocation, "MyFile.txt")替换你的?????
  • 非常感谢大卫。你让我开心。
猜你喜欢
  • 1970-01-01
  • 2011-12-17
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-01-08
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多