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

 

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

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

<appSettings>
<add key="SZHOOA01" value="weareMIS" />
<!--0不定时,直接执行一次.1按指定STime时间执行,2按指定ITime时间间隔执行,3混合定时先按STime开始第一次执行后按ITime时间间隔执行-->
<add key="Type" value="0" />
<add key="STime" value="00:10:00" />
<add key="ITime" value="00:20:00" />
<!--格式(时:分:秒):"xx:xx:xx"-->
<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();

 

posted @ 2012-04-01 10:15  Tom Fan  阅读(1073)  评论(0编辑  收藏  举报