2

I have been searching high and low for the proper way to use System::Configuration to create and modify a user.config file located under AppData/Local/myapplicationname/. I use the configuration manager to open a local user level configuration object. The user.config file does not exist yet under AppData/Local, so I call the Configuration::Save() method to create it (MSDN documentation states that this method will create the file if it does not exist).

Configuration^ C = ConfigurationManager::OpenExeConfiguration(ConfigurationUserLevel::PerUserRoamingAndLocal);
MessageBox::Show(C->FilePath); // Shows "rootpath/AppData/Local/myappname/user.config"
MessageBox::Show(C->HasFile.ToString()); // Shows "false" since user.config hasn't been created yet.
C->Save(ConfigurationSaveMode::Full);

And nothing happens, the user.config file is not created and there are no error messages. If I use Configuration::SaveAs() instead, I get the error message:

"The file name 'rootpath\AppData\Local\myappname\user.config' is invalid because the same file name is already referenced by the configuration hierarchy you have opened."

What am I doing wrong here? I'm very annoyed with MSDN's lack of explanation on how to use System::Configuration for anything besides app.config. I do not want to use app.config since the settings are user-level and can be changed at any time by the user. I would use app.config if I had to, but can't even do that because of UAC. Any help would be greatly appreciated. Thanks all!

pcdangio
  • 294
  • 2
  • 13

0 Answers0