Well, you can always write a custom configuration section and store whatever
you like in the file:
<configuration>
<configSections>
<add name="myConfigSection"
type="MyApp.Configuration.MyConfigSection, MyApp, Version=1.0.0.0,
Culture=neutral, PublicKeyToken=null"/>
</configSections>
<myConfigSection>
<codes>
<add key="1" value="an"/>
<add key="2" value="example"/>
</codes>
</myConfigSection>
<appSettings>...</appSettings>
</configuration>
Basically, you can do whatever you want with the configuration files - just
add a reference to System.Configuration and create a class that derives from
System.Configuration.ConfigurationSection. Note, the version number of my
assembly in the example was 1.0.0.0, the assembly wasn't signed, and i was
assuming the object would be located in the executable just for simplicity.
using System.Configuration;
namespace MyApp.Configuration {
public class MyConfigSection : ConfigurationSection {
public MyConfigSection() {
}
[ConfigurationProperty("codes", IsRequired = false)]
public Dictionary<string, string> Codes {
get { return (Dictionary<string, string>)this["codes"]; }
set { this["codes"] = value; }
}
}
}
That example is more than likely non-working, I was simply trying to show
you how the config file ties to the object you'll be using in your
application.
System.Configuration.Configuration config =
ConfigurationManager.OpenExeConfiguration();
MyConfigSection section =
(MyConfigSection)config.GetSection("myConfigSection");
You'll now have access to the section.Codes property containing your data
you wanted to store in the config file. Just don't forget, the config file
only loads once for the default appdomain. Any changes to it while the
application is executing will not take effect until the appdomain is
reloaded (aka the application is restarted).
HTH
[quoted text, click to view] "coconet" <coconet@community.nospam> wrote in message
news:0kot345fs104u5o1re6240m4mu4e0hfh7q@4ax.com...
>I have a list of value pairs represented as a
> Dictionary<String,String>. I would like to store them in my app.config
> file - how can I do that? I don't want to keep them in a regular text
> file.
>
> Thanks.
>