I would use App.config and access the settings using the ConfigurationManager.AppSettings class.
App.Config
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" />
</startup>
<appSettings>
<add key="Setting1" value="true"/>
<add key="Setting2" value="value"/>
</appSettings>
</configuration>
Access settings from your application with the following
bool setting1 = Convert.ToBolean(ConfigurationManager.AppSettings["Setting1"]);
string setting2 = ConfigurationManager.AppSettings["Setting2"];
To update settings create a static helper method
public static void UpdateAppSetting(string key, string value)
{
var configuration = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
configuration.AppSettings.Settings[key].Value = value;
configuration.Save();
ConfigurationManager.RefreshSection("appSettings");
}
See the link below for more examples.
1
solved I want to save user data on client’s machine for c# app [closed]