快精灵印艺坊 您身边的文印专家
广州名片 深圳名片 会员卡 贵宾卡 印刷 设计教程
产品展示 在线订购 会员中心 产品模板 设计指南 在线编辑
 首页 名片设计   CorelDRAW   Illustrator   AuotoCAD   Painter   其他软件   Photoshop   Fireworks   Flash  

 » 彩色名片
 » PVC卡
 » 彩色磁性卡
 » 彩页/画册
 » 个性印务
 » 彩色不干胶
 » 明信片
   » 明信片
   » 彩色书签
   » 门挂
 » 其他产品与服务
   » 创业锦囊
   » 办公用品
     » 信封、信纸
     » 便签纸、斜面纸砖
     » 无碳复印纸
   » 海报
   » 大篇幅印刷
     » KT板
     » 海报
     » 横幅

.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();

}









返回类别: 教程
上一教程: 根据函数名称定位函数
下一教程: Metadata and Reflection in .NET

您可以阅读与".Net配置文件常用配置说明"相关的教程:
· .NET下INI配置文件操作类
· 熟悉ASP.NET配置文件Web.config
· 如何使用.NET配置文件(一)
· 实例讲解.NET中资源文件的创建与使用
· ASP.NET中上传下载文件
    微笑服务 优质保证 索取样品