【发布时间】:2021-01-11 14:48:51
【问题描述】:
我在 VS 2019 中有一个 c# 脚本,现在我想将值写入文件,但我必须将 .txt 文件放在哪里?之后我想用 Inno Setup Compiler 制作一个 Setup.exe。
所以我的问题是,在我的 Programm 编程期间以及从 Setup.exe 安装 .exe 之后,我应该将文件放在哪里才能访问它。
我听说过这件事,但我不知道这是做什么的:
string filePath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "combinations.txt");
现在我在函数顶部设置权限,因为它提到了here,但我仍然遇到问题
[PermissionSet(SecurityAction.Demand, Name = "FullTrust")]
private void button4_Click(object sender, EventArgs e)
{
string date = DateTime.Now.ToString("g");
string exePath = Path.GetDirectoryName(System.Reflection.Assembly.GetEntryAssembly().Location);
string logFile = "combinations.txt";
if (File.Exists(Path.Combine(exePath, logFile)) == false)
File.Create(Path.Combine(exePath, logFile));
using (StreamWriter wr = File.AppendText(Path.Combine(exePath, logFile)))
{
wr.WriteLine(date + "|" + date);
wr.Close();
}
}
感谢您的帮助
【问题讨论】:
-
您是否尝试查看文档以了解该行代码?在这里为你Environment.GetFolderPath,Environement.SpecialFolder,Path.Combine
标签: c# visual-studio inno-setup