How to read key/value pairs from the appSettings section and put them in a dictionary c#

EDN Admin

Well-known member
Joined
Aug 7, 2010
Messages
12,794
Location
In the Machine
Hi everyone,<br/>
<br/>
I have for example a configuration file like this one:<br/>

<pre class="prettyprint <?xml version="1.0"?>
<configuration>
<appSettings>
<add key="ImageServerDataRoot" value="{arch}rchiveDataVols" />
<add key="ImageServerTempFileLocation" value="{arch}ArchiveData" />
<add key="ImageServerImageDataRoot" value="{arch}ArchiveData" />
<add key="ModuleStorage" value="{arch}ArchiveDataDerivedModules"/>
<add key="AshxPage" value="http://{hostname}/HttpHandlers/ScaleTest.ashx" />
<add key="Audit" value="{dir}Audits" />
<add key="ClientSettingsProvider.ServiceUri" value="" />
<add key="PluginsFolder" value="{dir}Generatorx64Plugins"/>
</appSettings>
.....
</configuration>[/code]
and I load it like so, to my console application(Visual studio 2010-c#):<br/>

<pre class="prettyprint namespace XMLTest
{
class test
{
XmlDocument xdoc = null;

public void LoadXML(string pathToXML)
{
xdoc = new XmlDocument();
xdoc.Load(pathToXML);
}
}
[/code]
and this is how I call it in my main:

<pre class="prettyprint test test = new test(); test.LoadXML(args[0]); [/code]
Now I want it to read these key/value pairs from the appSettings section and put them in a dictionary.<br/>
can someone help me out on how to do it-examples, links, tips anything is welcome.<br/>


View the full article
 
Back
Top