.net 读取非标准配置文件的小例子

这篇文章介绍了.net 读取非标准配置文件的小例子,有需要的朋友可以参考一下

代码如下:
复制代码 代码如下:

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; 
       } 

配置文件目录结构:
复制代码 代码如下:

 
 
     
         
   
 
 

调用:
复制代码 代码如下:

//里面的参数为配置文件的key  
string strConn=Config("ConnectionString"); 

以上就是.net 读取非标准配置文件的小例子的详细内容,更多请关注0133技术站其它相关文章!

赞(0) 打赏
未经允许不得转载:0133技术站首页 » ASP编程