• 企业400电话
  • 微网小程序
  • AI电话机器人
  • 电商代运营
  • 全 部 栏 目

    企业400电话 网络优化推广 AI电话机器人 呼叫中心 网站建设 商标✡知产 微网小程序 电商运营 彩铃•短信 增值拓展业务
    .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; 
           } 

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

    ?xml version="1.0" encoding="utf-8" ?> 
    configuration> 
        appSettings> 
            add key="ConnectionString" value="Server=(local);Database=DB;User Id=sa;Password=123" /> 
        /appSettings> 
    /configuration> 

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

    //里面的参数为配置文件的key  
    string strConn=Config("ConnectionString"); 
    您可能感兴趣的文章:
    • asp.net 在处理向该请求提供服务所需的配置文件时出错
    • .NET 2.0获取配置文件AppSettings和ConnectionStrings节数据的方法
    • 认识ASP.NET配置文件Web.config
    上一篇:将.aspx转换为.htm的两种方法
    下一篇:asp.Net JS取母板页控件值的简单方法
  • 相关文章
  • 

    © 2016-2020 巨人网络通讯

    时间:9:00-21:00 (节假日不休)

    地址:江苏信息产业基地11号楼四层

    《增值电信业务经营许可证》 苏B2-20120278

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