中国IT动力,最新最全的IT技术教程
最新100篇 | 推荐100篇 | 专题100篇 | 排行榜 | 搜索 | 在线API文档 | 网通镜像
首 页 | 程序开发 | 操作系统 | 软件应用 | 图形图象 | 网络应用 | 精文荟萃 | 教育认证 | 硬件维护 | 未整理篇 | 站长教程
ASP JS PHP工程 ASP.NET 网站建设 UML J2EESUN .NET VC VB VFP 网络维护 数据库 DB2 SQL2000 Oracle Mysql
服务器 Win2000 Office C DreamWeaver FireWorks Flash PhotoShop 上网宝典 CorelDraw 协议大全 网络安全 微软认证
硬件维护  CPU  主板  硬盘  内存  显卡  显示器  键盘鼠标  声卡音箱  打印机  机箱电源  BIOS  网卡  C#  Java  Delphi  vs.net2005
  当前位置:> 程序开发 > 编程语言 > .NET > 临时文章
.Net配置文件常用配置说明
作者:未知 时间:2005-07-27 21:35 出处:CSDN 责编:chinaitpower
              摘要:.Net配置文件常用配置说明

 

配置文件内容如下:

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

<configuration>

     <configSections>      

         <section name="mySection" type="System.Configuration.NameValueSectionHandler"/>

         <section name="mySingleTagSection" type="System.Configuration.SingleTagSectionHandler"/>

         <section name="myDictionarySection" type="System.Configuration.DictionarySectionHandler"/>

 

         <sectionGroup name="mySections">

              <section name="mySection1" type="System.Configuration.NameValueSectionHandler"/>

              <section name="mySection2" type="System.Configuration.NameValueSectionHandler"/>

         </sectionGroup>

     </configSections>

    

    <mySection>

         <add key="key1" value="value1" />

        <add key="key2" value="value2" />

    </mySection>

   

    <mySingleTagSection setting1="value1" setting2="value2" setting3="value3" />

 

     <myDictionarySection>

         <add key="DictionarySectionKey1" value="DictionarySectionValue1"/>

         <add key="DictionarySectionKey2" value="DictionarySectionValue2"/>

         <add key="DictionarySectionKey3" value="DictionarySectionValue3"/>

     </myDictionarySection>

       

     <mySections>

         <mySection1>

              <add key="mySection1_key1" value="mySection1_value1" />

              <add key="mySection1_key2" value="mySection1_value2" />         

         </mySection1>

         <mySection2>

              <add key="mySection2_key1" value="mySection2_value1" />

              <add key="mySection2_key2" value="mySection2_value2" />

         </mySection2>

     </mySections>

    

     <appSettings>

        <add key="appkey1" value="appvalue1" />

        <add key="appkey2" value="appvalue2" />   

    </appSettings>

</configuration>

代码片断如下:

private static void TestAppSettings()

{

     Console.WriteLine("TestAppSettings ...");

 

     NameValueCollection config = ConfigurationSettings.AppSettings;

    

     Console.WriteLine("value1:" + config["key1"]);

     Console.WriteLine("value2:" + config["key2"]);

 

     Console.WriteLine();

}

private static void TestSection()

{

     Console.WriteLine("TestSection ...");

 

     NameValueCollection config ;

     config = (NameValueCollection)ConfigurationSettings.GetConfig("mySection");

     Console.WriteLine("value1:" + config["key1"]);

     Console.WriteLine("value2:" + config["key2"]);

 

     Console.WriteLine();

}

 

private static void TestSingleTagSection()

{

     Console.WriteLine("TestSingleTagSection ...");

 

     IDictionary dic ;

     dic = (IDictionary)ConfigurationSettings.GetConfig("mySingleTagSection");

     Console.WriteLine("value1:" + dic["setting1"]);

     Console.WriteLine("value2:" + dic["setting2"]);

     Console.WriteLine("value3:" + dic["setting3"]);

 

     Console.WriteLine();

}

 

private static void TestDictionarySection()

{

     Console.WriteLine("TestDictionarySection ...");

 

     IDictionary dic ;

     dic = (IDictionary)ConfigurationSettings.GetConfig("myDictionarySection");

     Console.WriteLine("DictionarySectionValue1:" + dic["DictionarySectionKey1"]);

     Console.WriteLine("DictionarySectionValue2:" + dic["DictionarySectionKey2"]);

     Console.WriteLine("DictionarySectionValue3:" + dic["DictionarySectionKey3"]);

 

     Console.WriteLine();

}

 

private static void TestSectionGroup()

{

     Console.WriteLine("TestSectionGroup ...");

 

     NameValueCollection config1 ;

     NameValueCollection config2 ;

     config1 = (NameValueCollection)ConfigurationSettings.GetConfig("mySections/mySection1");

     config2 = (NameValueCollection)ConfigurationSettings.GetConfig("mySections/mySection2");

 

     Console.WriteLine("mySections/mySections1/value1:" + config1["mySection1_key1"]);

     Console.WriteLine("mySections/mySections1/value2:" + config1["mySection1_key2"]);

 

     Console.WriteLine("mySections/mySections2/value1:" + config2["mySection2_key1"]);

     Console.WriteLine("mySections/mySections2/value2:" + config2["mySection2_key2"]);

 

     Console.WriteLine();

}

 


关闭本页
 
首页 | 投资与合作 | 服务条款 | 隐私政策 | 收藏本站 | 设为首页 | 新用户注册 | 免责声明 | 使用帮助
Copyright ©2005-2008 chinaitpower.com All rights reserved. www.chinaitpower.com 版权所有