App.Config file in console application C#(控制台应用程序 C# 中的 App.Config 文件)
问题描述
我有一个控制台应用程序,我想在其中写入文件名.
I have a console application in which I want to write the name of a file.
Process.Start("blah.bat");
通常,通过将文件 'blah.bat' 的名称写入 Properties 文件中的 Settings 文件,我会在 Windows 应用程序中拥有类似的东西强>.
但是,在这里我没有找到任何 Settings 文件,我添加了一个 app.config 用于相同目的.
Normally, I would have something like that in windows application by writing the name of the file 'blah.bat' to Settings file in Properties.
However, here I didn't find any Settings file and I added an app.config for the same purpose.
我不确定在 app.config 中写什么,这会导致我实现与 Windows 窗体 中类似的事情.
I am not sure what to write here in app.config, that would lead to me to achieve similar thing as in Windows Forms.
例如:在 Windows 窗体中.Process.Start(Properties.Settings.Default.BatchFile);
其中 BatchFile 是属性设置文件中的字符串.
For eg: In windows forms. Process.Start(Properties.Settings.Default.BatchFile);
where BatchFile is a string in settings file in Properties.
推荐答案
您可以在项目中添加对 System.Configuration 的引用,然后:
You can add a reference to System.Configuration in your project and then:
使用 System.Configuration;
然后
string sValue = ConfigurationManager.AppSettings["BatchFile"];
使用像这样的 app.config 文件:
with an app.config file like this:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<appSettings>
<add key="BatchFile" value="blah.bat" />
</appSettings>
</configuration>
这篇关于控制台应用程序 C# 中的 App.Config 文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:控制台应用程序 C# 中的 App.Config 文件
基础教程推荐
- 重新排序 WPF TabControl 中的选项卡 2022-01-01
- SonarQube C# 分析失败“不是指针的有效行偏移" 2022-01-01
- 如果条件可以为空 2022-01-01
- 更新 Visual Studio 中的 DataSet 结构以匹配新的 SQL 数据库结构 2022-01-01
- 从 C# 控制相机设备 2022-01-01
- 在 VB6 或经典 ASP 中使用 .NET 2022-01-01
- Mono https webrequest 失败并显示“身份验证或解密失败" 2022-01-01
- C# 9 新特性——record的相关总结 2023-04-03
- 获取C#保存对话框的文件路径 2022-01-01
- 将数据集转换为列表 2022-01-01
