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

查看:375
本文介绍了在控制台应用程序C#App.config文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我有我想要写一个文件名的控制台应用程序。


I have a console application in which I want to write the name of a file.

过程。开始(blah.bat);


通常情况下,我会通过写文件'嗒嗒的名称在Windows应用程序类似的东西。蝙蝠设置属性文件中。

然而,在这里我没有找到任何设置文件,我添加一个app.config为同一目的。

Process.Start("blah.bat");

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窗体

。对于例如:在Windows窗体。的Process.Start(Properties.Settings.Default.BatchFile);

,其中是批处理文件中设置一个字符串属性文件

I am not sure what to write here in app.config, that would lead to me to achieve similar thing as in windows forms.
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;

然后

S值的字符串= ConfigurationManager.AppSettings [批处理文件];

的app.config 文件是这样的:

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
   <appSettings>
       <add key="BatchFile" value="blah.bat" />
   </appSettings>
</configuration>

这篇关于在控制台应用程序C#App.config文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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