110


ファイルの名前を書きたいコンソールアプリケーションがあります。

Process.Start("blah.bat");

通常、ファイルの名前をPropertiesのSettingsファイルに'blah.bat'書き込むことにより、Windowsアプリケーションでそのようなものを作成します。ただし、ここでは設定ファイル が見つからず、同じ目的でapp.configを追加しました。

ここでapp.configに何を書くべきかわかりません。これにより、 Windows Formsと同様のことが達成されます。

例: Windows フォーム。プロパティの設定ファイルの文字列ですProcess.Start(Properties.Settings.Default.BatchFile);
BatchFile

4

3 に答える 3

248

System.Configurationプロジェクトに参照を追加してから、次のことができます。

using System.Configuration;

それから

string sValue = ConfigurationManager.AppSettings["BatchFile"];

次のようなファイルを使用しapp.configます。

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
   <appSettings>
       <add key="BatchFile" value="blah.bat" />
   </appSettings>
</configuration>
于 2012-04-09T05:28:49.390 に答える