我有一个控制台应用程序,我想在其中写入文件名.
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 文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!
读取 XML 时忽略空格Ignore whitespace while reading XML(读取 XML 时忽略空格)
带有检查空元素的 XML 到 LINQXML to LINQ with Checking Null Elements(带有检查空元素的 XML 到 LINQ)
在 C# 中读取带有未闭合标签的 XMLReading XML with unclosed tags in C#(在 C# 中读取带有未闭合标签的 XML)
在 C# 中使用 Html 敏捷性解析表格、单元格Parsing tables, cells with Html agility in C#(在 C# 中使用 Html 敏捷性解析表格、单元格)
使用 LINQ 从 xml 中删除元素delete element from xml using LINQ(使用 LINQ 从 xml 中删除元素)
解析格式错误的 XMLParse malformed XML(解析格式错误的 XML)