C # Implementation of appsettings node read and modify methods

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.