zoukankan      html  css  js  c++  java
  • 从网上找的配置文件类,比我原来的好,能用在winform和webform项目中

    能用在两种项目中,比较不错
    using System;
    using System.Configuration;
    using System.Reflection;
    using System.Web;
    using System.Xml;

    public enum ConfigFileType


    namespace TexSelect
    {
        
    /**//// <summary>
        
    /// 配置文件操作类
        
    /// </summary>

        public class AppConfig : AppSettingsReader
        

    }

    使用方法:
    string sqlConnText="";

                AppConfig appconfig
    =new AppConfig();
                appconfig.ConfigType
    =(int)ConfigFileType.WebConfig;

                sqlConnText
    =(string)appconfig.GetValue("SQLConnectionString",sqlConnText.GetType());

    设置方法:
    项目为web项目,则配置信息存在web.config文件中,使用时:appconfig.ConfigType=(int)ConfigFileType.WebConfig;
    项目为win项目,则配置信息存在app.config文件中,使用时:appconfig.ConfigType=(int)ConfigFileType.AppConfig;

    配置文件示例:
    不论在web.config中还是在app.config中都放在<configuration></configuration>之间,格式如下:
     <appSettings>

         
    <add key="SQLConnectionString" value="Server=127.0.0.1;database=tex;uid=sa;pwd=sa" />
             
      
    </appSettings>

  • 相关阅读:
    Ognl表达式基本原理和使用方法
    Struts的拦截器
    Struts框架的核心业务
    Struts2框架基础
    Struts的文件上传下载
    .JavaWeb文件上传和FileUpload组件使用
    mysql数据库连接与锁查询
    关于MyBatis的@Mapper和@MapperScan注解的一点思考
    Hystrix报错java.util.concurrent.TimeoutException: null
    The Hystrix timeout of 2000ms for the command xxx is set lower than the combination of the Ribbon read and connect timeout, 4000ms.
  • 原文地址:https://www.cnblogs.com/telephoner/p/236929.html
Copyright © 2011-2022 走看看