【问题标题】:How to read the text file from the Application Directory text file如何从应用程序目录文本文件中读取文本文件
【发布时间】:2014-01-10 03:06:24
【问题描述】:

我在 Windows 窗体应用程序的应用程序项目类路径目录中有一个文本文件。现在在安装时,我正在尝试将文本值写入文本文件。这是我的文本文件的安装程序类代码..

File.WriteAllText(AppDomain.CurrentDomain.BaseDirectory + @"\" + "ConnectionString.txt",param3);

安装后,我想检索在“ConnectionString.txt”文件中输入的文本并在应用程序中使用它,但我不知道如何检索文本文件中存在的文本值。

【问题讨论】:

标签: c# text-files windows-applications applicationdomain


【解决方案1】:

试试下面的代码sn-p

Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "ConnectionString.txt")

读取文本文件

string result = File.ReadAllText(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "ConnectionString.txt"));

【讨论】:

  • 你可以完全忽略这里的路径——无论如何它都是相对于调用程序集的位置。
  • @geek 先生,我收到此错误“System.IO.DirectoryNotFoundException:找不到路径的一部分'C:\Users\vikas\AppData\Roaming\Microsoft\Windows\Start Menu\ Programs\TechSoft CallBill\TechSoft CallBill.exe\ConnectionString.txt'。"
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2018-01-03
  • 1970-01-01
  • 2015-07-10
  • 1970-01-01
  • 2018-03-19
相关资源
最近更新 更多