0
我正在處理用戶應該定義輸出目錄的應用程序。之後看了很多關於的app.config也關於INI(here表示,不建議和.NET還沒有任何類或命名空間來閱讀)和TXT(有點乏味),我決定去到app.config。所以我寫了這個代碼:app.config或TXT/INI用於保存配置選項?
// Here I save to app.config file
private void button1_Click(object sender, EventArgs e)
{
if (textBox2.Text != "")
{
oConfig.AppSettings.Settings.Add("directorio_bases", textBox2.Text);
oConfig.Save(ConfigurationSaveMode.Modified);
ConfigurationManager.RefreshSection("appSettings");
textBox1.Text = ConfigurationManager.AppSettings["directorio_bases"];
}
else
{
MessageBox.Show("Debes seleccionar una ruta donde guardar las bases generadas", "Error",
MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
// Here I read from app.config file just for informative purpose only
private void ConfigurationUserControl_Load(object sender, EventArgs e)
{
textBox1.Text = ConfigurationManager.AppSettings["directorio_bases"];
}
// Here is where I get the path to the folder
private void button2_Click(object sender, EventArgs e)
{
if (folderBrowserDialog1.ShowDialog() == DialogResult.OK)
{
textBox2.Text = folderBrowserDialog1.SelectedPath;
}
}
而且代碼的工作程序執行期間罰款,但是當我關閉/打開的程序價值迷失。所以我的問題是:
- 我做錯了什麼?我的意思是爲什麼價值觀不被保留?
- 您的使用過app.config,config.ini或config.txt文件嗎?我需要聽取您對此主題的意見
感謝@ user797717它的工作現在 – Reynier 2013-04-27 23:24:21