C# · 12月 21, 2021

C# 读取指定路径配置文件的方法

复制代码 代码如下:
ExeConfigurationFileMap map = new ExeConfigurationFileMap();
map.ExeConfigFilename = @”F:\App1.config”; ;
Configuration config = ConfigurationManager.OpenMappedExeConfiguration(map,ConfigurationUserLevel.None);
string connstr = config.ConnectionStrings.ConnectionStrings[“connStr”].ConnectionString;
Message@R_690_2419@.Show(connstr);
string key = config.AppSettings.Settings[“key”].Value;
Message@R_690_2419@.Show(key);