add settings to config file c#
// Write Setting
// The scope of the settings file must be set to user in order for it not to be read-only
SettingsFile.Default.MySetting = "A setting";
SettingsFile.Default.Save(); // In order to save all the changes
// Read Setting
string myvalue = SettingsFile.Default.MySetting; // retrieve a setting of type string
3.67
3
//Must install package System.Configuration.ConfigurationManager
//APPLICATION CONFIG FILE
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<appSettings>
<add key="Key0" value="0" />
<add key="Key1" value="1" />
<add key="Key2" value="2" />
</appSettings>
</configuration>
//CODE
using System.Configuration;
using System.Collections.Specialized;
//READ Value of Setting Key0
string sAttr = ConfigurationManager.AppSettings.Get("Key0");
Thank you!
3
0
Are there any code examples left?
New code examples in category C#