Home > Backend Development > C#.Net Tutorial > Specific methods of operating config files in C#

Specific methods of operating config files in C#

高洛峰
Release: 2016-12-24 13:04:56
Original
1518 people have browsed it

The following is the definition of app.config or web.config, which defines a parameter with the key Isinit and the value false



< ;add key ="IsInit" value="false"/>

The following are the method definitions for reading and writing config files:

Write:

internal void settingApp_write(string key, string val) 
 { 
     System.Configuration.Configuration config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None); 
 config.AppSettings.Settings["IsInit"].Value = val; 
 config.Save(ConfigurationSaveMode.Modified); 
 ConfigurationManager.RefreshSection("appSettings"); 
 }
Copy after login

Read :

internal string settingApp_read(string key) 
{ 
    var val = ConfigurationManager.AppSettings[key]; 
    return val; 
}
Copy after login

Usage:

Write test:

settingApp_write("IsInit","true");

Take out test:

var setting = settingApp_read("Isinit");

The modifications at this level are Project-level config file modification is the operation of the config file in the Bin directory of your final program.


For more related articles on specific methods of operating config files in C#, please pay attention to the PHP Chinese website!


Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template