title: WPF - Modify Configuration settings during runtime
body: <p>I'm creating a WPF application. It works fine in Visual Studio. But, whenever I modify configuration settings through application after installation, It throws error 'Error occurred loading a configuration file: Access to path c:\Program Files (x86)\… denied'. I can't run the program as Admin every time as per requirement. Is there any way to solve this?</p>
  
  <pre><code>var config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
  var connectionStringsSection = (ConnectionStringsSection)config.GetSection("connectionStrings");connectionStringsSection.ConnectionStrings["cn"].ConnectionString = "data source=" + txtServer.Text + ";database=" + txtDatabase.Text + ";User ID=" + txtUserID.Text + ";Password=" + pwdPassword.Password;
  config.Save(ConfigurationSaveMode.Modified);
  ConfigurationManager.RefreshSection("connectionStrings");
  
  config.Save(ConfigurationSaveMode.Modified);
  
  // Force a reload of the changed section.
  ConfigurationManager.RefreshSection("appSettings");
  </code></pre>