Well, I read the Hari Gillal link in which one user suggested editing the app.config file directly, that is, the XML file.
Therefore, in the project properties → settings, I create the parameters I need. Then, to load the parameter into the code, I do the following:
_myViewModelProperty = MyApp.Properties.Settings.Default.MyParam1;
This way, I can easily read the configuration parameter information. It is typed, so during debugging I see if this name is correct or not.
To update the configuration file, I am editing the app.config file using the .NET XML libraries.
System.Xml.XmlDocument xml = new System.Xml.XmlDocument(); xml.Load(AppDomain.CurrentDomain.SetupInformation.ConfigurationFile); System.Xml.XmlNode node; node = xml.SelectSingleNode("configuration/applicationSettings/MyApp.Properties.Settings/setting[@name='myparam1']"); node.ChildNodes[0].InnerText = myNewValue; xml.Save(AppDomain.CurrentDomain.SetupInformation.ConfigurationFile);
Thus, I create an XML document (xml variable) and load the information from the app.config file. Then I look for the node that I want to update, update its information (InnerText property), and finally save the changes.
That way I can update app.config. This is what I want, because in the portable application only one user will use it, and I want this configuration to be applied on any computer on which I run the application.
source share