Tutorials to .com

Tutorials to .com » Dotnet » Winform » [dotNET] how to read the configuration file ConfigurationSettings.AppSettings.GetValues more than the value with the Key

[dotNET] how to read the configuration file ConfigurationSettings.AppSettings.GetValues more than the value with the Key

Print View , by: iSee ,Total views: 10 ,Word Count: 451 ,Date: Sun, 23 Aug 2009 Time: 4:09 AM

Author: Cheng Yun @ Ultrapower

By default,
string [] strArray = System.Configuration.ConfigurationSettings.AppSettings.GetValues ( "Uri");
Is the configuration file can not read more than the value of the same Key. Configuration as follows:
<appSettings>

<add key="Uri" value="uri1"/>
<add key="Uri" value="uri2"/>
<add key="Uri" value="uri3"/>

</ appSettings>
MSDN tells us to use the time GetValues is not only read the last value.
http://www.codeproject.com/dotnet/namevaluemultiple.asp tells us that
Can only do so:
The first step:
The establishment of a separate class library MultipleSectionHandler, the NameValueMultipleSectionHandler.cs added, and adding to our MultipleSectionHandler.csproj project;
Step Two:
Compiler MultipleSectionHandler, generated MultipleSectionHandler.dll;
The third step:
WebApp application will be added to the Web.config file
<configSections>
<remove name="appSettings" />
<section name="appSettings" type="MyCompany.Configuration.NameValueMultipleSectionHandler, MultipleSectionHandler" />
</ configSections>
Suggests that will be used to read the appSettings our own to deal with MultipleSectionHandler.
Step four:
At this time we can for the Web.config:
<appSettings>

<add key="Uri" value="uri1"/>
<add key="Uri" value="uri2"/>
<add key="Uri" value="uri3"/>

</ appSettings>
By
string [] strArray = System.Configuration.ConfigurationSettings.AppSettings.GetValues ( "Uri");
To read.


.Net Windows development Articles


Can't Find What You're Looking For?


Rating: Not yet rated

Comments

No comments posted.