This article describes the C # implementation of appsettings node read and modify the method, share to everyone for your reference. Here's how:
The key code is as follows:
The code is as follows:
public static string Getappsettingsvalue (String key)
{
Configurationmanager.refreshsection ("appSettings");
Return Configurationmanager.appsettings[key]?? String. Empty;
}
public static bool Updateappsettings (string key, String value)
{
var _config = configurationmanager.openexeconfiguration (Configurationuserlevel.none);
if (!_config. HasFile)
{
throw new ArgumentException ("The program configuration file is missing! ”);
}
Keyvalueconfigurationelement _key = _config. Appsettings.settings[key];
if (_key = = null)
_config. APPSETTINGS.SETTINGS.ADD (key, value);
Else
_config. Appsettings.settings[key]. Value = value;
_config. Save (configurationsavemode.modified);
return true;
}
I hope this article is helpful to everyone's C # programming.
In addition to the Declaration,
Running GuestArticles are original, reproduced please link to the form of the address of this article
C # Implementation of appsettings node read and modify methods
This address: http://www.paobuke.com/develop/c-develop/pbk23438.html
Related Content C # design Pattern template method pattern implementation ASP. NET custom control password strength detection devexpress GridView automatic Scrolling effect C # network crawler code share C # Simple Crawl tool parsing C # design pattern implementation of the adapter pattern in programming
. NET random generation Chinese characters of Delegate usages in C # The method of reading a specified line from a file or standard input device analysis of two-dimensional array difference in C # and Java
C # Implementation of appsettings node read and modify methods