title: use ConfigurationManager to store user values in a file that is separate from the app config
body: <p>Ok, I've just about given up on this.</p>
  
  <p>I would like to be able to record user preferences using a user config file, which would be referenced from the app config file.  I am trying to do this with <code>ConfigurationManager</code> and an app config file.  I can read just fine from the user settings, but setting them is a whole other problem.  I would like to keep the app settings separate from the user settings in two different files.
  <hr><hr></p>
  
  <p>When I use this:</p>
  
  <pre><code>&lt;appSettings file="user.config"&gt;
    &lt;/appSettings&gt;
  </code></pre>
  
  <p>and user.config looks like:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8" ?&gt;
  &lt;appSettings&gt;
    &lt;add key="localSetting" value="localVal"/&gt;
  &lt;/appSettings&gt;
  </code></pre>
  
  <p>I can use ConfigurationManager to READ the local setting, but not to save to the file.</p>
  
  <pre><code>var oldLocVal = ConfigurationManager.AppSettings["localSetting"]; 
  ConfigurationManager.AppSettings.Set("localSetting", "newLocalValue"); // Doesn't save to file.
  </code></pre>
  
  <p><hr><hr>
  If instead my user.config file is:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8" ?&gt;
  &lt;configuration&gt;
    &lt;appSettings&gt;
      &lt;add key="localSetting" value="localVal"/&gt;
    &lt;/appSettings&gt;
  &lt;/configuration&gt;
  </code></pre>
  
  <p>I would then like to call and save the AppSettings in this way:</p>
  
  <pre><code>var uMap = new ConfigurationFileMap("user.config");
  var uConfig = ConfigurationManager.OpenMappedMachineConfiguration(uMap);
  var oldLocalVarFromConfig = uConfig.AppSettings.Settings["localSetting"]; // NO
  uConfig.AppSettings.Settings.Remove("localSetting");                      // NO
  uConfig.AppSettings.Settings.Add("localSetting", "newValue");
  uConfig.Save();
  </code></pre>
  
  <p>but it won't let me access the configuration's app settings.  (It has a problem casting something as an AppSettings)
  <hr><hr>
  I also tried with <code>configSource</code> instead of <code>file</code> attributes in the app config <code>appSettings</code> element.</p>
  
  <p>I was using the <a href="http://msdn.microsoft.com/en-us/library/system.configuration.configurationmanager%28v=VS.90%29.aspx" rel="nofollow">examples here</a> for help, but unfortunately it wasn't enough.</p>
  
  <p>Thanks in advance.</p>