Normally we use app.config file to store some config values. as we all know, we can easily read values from app.config using C#. but we rarely update that file in run time. but this is also possible in C#.
here i have explained how to write back(Add new keys or update values of certain key) to app.config file in run time.
/// <summary>
/// Update app config values
/// </summary>
/// <param name="key">app config key</param>
/// <param name="value">app config value</param>
public static void UpdateAppSettings(string key, string value)
{
// Give the correct path of an app.config file
Configuration config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
if (ConfigurationManager.AppSettings[key] == null)
{
config.AppSettings.Settings.Add(key, value);
}
else
{
config.AppSettings.Settings[key].Value = value;
}
config.Save(ConfigurationSaveMode.Modified);
ConfigurationManager.RefreshSection("appSettings");
}
Write a main method and call this function to update app.config values. cool :)
here i have explained how to write back(Add new keys or update values of certain key) to app.config file in run time.
/// <summary>
/// Update app config values
/// </summary>
/// <param name="key">app config key</param>
/// <param name="value">app config value</param>
public static void UpdateAppSettings(string key, string value)
{
// Give the correct path of an app.config file
Configuration config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
if (ConfigurationManager.AppSettings[key] == null)
{
config.AppSettings.Settings.Add(key, value);
}
else
{
config.AppSettings.Settings[key].Value = value;
}
config.Save(ConfigurationSaveMode.Modified);
ConfigurationManager.RefreshSection("appSettings");
}
Write a main method and call this function to update app.config values. cool :)
3 comments:
ninest123 16.03
ray ban sunglasses, cheap oakley sunglasses, replica watches, michael kors outlet, oakley sunglasses, jordan shoes, prada handbags, nike outlet, nike air max, nike free, louis vuitton, tiffany and co, ugg boots, louboutin outlet, ray ban sunglasses, louis vuitton outlet, burberry outlet online, michael kors outlet, chanel handbags, uggs on sale, tiffany jewelry, louis vuitton outlet, michael kors outlet, oakley sunglasses, oakley sunglasses, louboutin shoes, prada outlet, ugg boots, ray ban sunglasses, ugg boots, burberry, replica watches, michael kors outlet, tory burch outlet, longchamp outlet, michael kors outlet, louis vuitton, michael kors, polo ralph lauren outlet, longchamp outlet, louis vuitton, polo ralph lauren outlet, louboutin, oakley sunglasses, gucci outlet, ugg boots, christian louboutin outlet, nike air max, longchamp
zzzzz2018.8.27
pandora jewelry
jordan shoes
ralph lauren uk
giuseppe zanotti
canada goose jackets
coach outlet
kate spade outlet online
tods outlet
converse trainers
canada goose jackets
الروضة
صباغ فى الشارقة
شركات صيانة عامة في الشارقة
Post a Comment