Get the App
SLTechnology News&Howtos  ›  Development  › 

How to read non-standard configuration files with .net

Shulou Source: shulou.com Published: 2022-06-03 06:57:24 11月15日 Update

This article focuses on "how to use. Net to read non-standard configuration files", interested friends may wish to take a look. The method introduced in this paper is simple, fast and practical. Now let the editor take you to learn how to read non-standard configuration files with. Net.

The code is as follows:

The copy code is as follows:

Public static string Config (string key)

{

ExeConfigurationFileMap file = new ExeConfigurationFileMap ()

File.ExeConfigFilename = @ "Providers\\ Provider.config"

Configuration config = ConfigurationManager.OpenMappedExeConfiguration (file, ConfigurationUserLevel.None)

AppSettingsSection appsection = (AppSettingsSection) config.GetSection ("appSettings")

Return appsection.Settings[key] .Value

}

Configuration file directory structure:

The copy code is as follows:

Call:

The copy code is as follows:

/ / the parameter in it is the key of the configuration file

String strConn=Config ("ConnectionString")

At this point, I believe you have a deeper understanding of "how to read non-standard configuration files with. Net". You might as well do it in practice. Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!

Tags: Code file configuration standard content learning practical deeper interest parameter practicality practical easy to operate method more friends directory structure website channel Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno macOS Shulou Tech Info MariaDB OPPO Reno MySQL