控制台应用程序 C# 中的 App.Config 文件 [英] App.Config file in console application C#

查看:20
本文介绍了控制台应用程序 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 文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆