C# 保存配置选项的app.config或TXT/INI?
我正在开发一个应用程序,用户应该在其中定义一个输出目录。在阅读了大量关于app.config和ini(表示不推荐使用,并且.NET没有任何类或名称空间来阅读它们)和txt(有点乏味)的内容后,我决定转到app.config。所以我写了这段代码:C# 保存配置选项的app.config或TXT/INI?,c#,.net,app-config,C#,.net,App Config,我正在开发一个应用程序,用户应该在其中定义一个输出目录。在阅读了大量关于app.config和ini(表示不推荐使用,并且.NET没有任何类或名称空间来阅读它们)和txt(有点乏味)的内容后,我决定转到app.config。所以我写了这段代码: // Here I save to app.config file private void button1_Click(object sender, EventArgs e) { if (textBox2.Tex
// 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文件?我需要听听你对这个话题的看法