2013-04-27 38 views
0

我正在处理用户应该定义输出目录的应用程序。之后看了很多关于的app.config也关于INIhere表示,不建议和.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文件吗?我需要听取您对此主题的意见

回答

2

您是否尝试手动运行可执行文件(例如,从bin文件夹中)? 如果您在调试模式下运行应用程序,则不会修改app.config文件。

请看看下面的链接: C# - app config doesn't change

+0

感谢@ user797717它的工作现在 – Reynier 2013-04-27 23:24:21