C# 读取配置文件信息方法

 

配置文件App.config内容如下:

xml version="1.0" encoding="utf-8" ?>
<configuration>

<appSettings>
<add key="SZHOOA01" value="weareMIS" />

<add key="Type" value="0" />
<add key="STime" value="00:10:00" />
<add key="ITime" value="00:20:00" />

<add key="ClientSettingsProvider.ServiceUri" value="" />
appSettings>
<connectionStrings>
<add name="ConnectionStringMysql" connectionString="Data Source=188.20.1.54;User ID=router_user;Password=fxj;Persist Security Info=True;Database=skyaig" />
<add name="Default_Conn" connectionString="Data Source=188.20.1.121;Initial Catalog=Test;User ID=admin;Password=abc.123" providerName="System.Data.SqlClient" />
connectionStrings>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0"/>
startup>
configuration>

读取字段的方法如下:

      

 string  _localconnstr = ConfigurationManager.ConnectionStrings["Default_Conn"].ToString();
string _supplierconnstr = ConfigurationManager.ConnectionStrings["ConnectionStringMysql"].ToString();
string Type = ConfigurationManager.AppSettings["Type"].ToString();
string STime = ConfigurationManager.AppSettings["STime"].ToString();
string ITime = ConfigurationManager.AppSettings["ITime"].ToString();

 

转载于:https://www.cnblogs.com/fanxiaojun/archive/2012/04/01/2428042.html

你可能感兴趣的:(C# 读取配置文件信息方法)