|
-
Sep 21st, 2010, 09:21 AM
#1
Thread Starter
Frenzied Member
[RESOLVED] Storing Groups of Values in the App.Config and reading the values
I have edited my Settings using the GUI which has given me an App.Config Similar to below. However the value I am interested in DevEngineers.
I would Ideally like a group of Dev Engineers stored in here and then in my code be able to loop through all the names/values of the Dev Engineers held in the App.Config.
COuld someone please point me where I need to go with this. I mainly mean in terms of setting up the grouping as I found some MSDN Code which I should be able to modify for retreiving the data.
HTML Code:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<configSections>
<sectionGroup name="applicationSettings" type="System.Configuration.ApplicationSettingsGroup, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=XXXXXXX" >
<section name="UsageReport.Properties.Settings" type="System.Configuration.ClientSettingsSection, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=XXXXXXX" requirePermission="false" />
</sectionGroup>
</configSections>
<connectionStrings>
<add name="UsageReport.Properties.Settings.ConnectionStringDev"
connectionString="Data Source=XXXXXXX;Initial Catalog=XXXXXXX;Integrated Security=True"
providerName="System.Data.SqlClient" />
<add name="UsageReport.Properties.Settings.ConnectionStringProd"
connectionString="Data Source=XXXXXXX;Initial Catalog=XXXXXXX;Integrated Security=True"
providerName="System.Data.SqlClient" />
</connectionStrings>
<applicationSettings>
<CRSUsageReport.Properties.Settings>
<setting name="CommandTimeout" serializeAs="String">
<value>600</value>
</setting>
<setting name="Dev_Engineers" serializeAs="String">
<value>Burt</value>
</setting>
</UsageReport.Properties.Settings>
</applicationSettings>
</configuration>
Code:
static void GetAppSettings()
{
// Get the appSettings key,value pairs collection.
NameValueCollection appSettings =
WebConfigurationManager.AppSettings
as NameValueCollection;
// Get the collection enumerator.
IEnumerator appSettingsEnum =
appSettings.GetEnumerator();
// Loop through the collection and
// display the appSettings key, value pairs.
int i = 0;
Console.WriteLine("[Display appSettings]");
while (appSettingsEnum.MoveNext())
{
string key = appSettings.AllKeys[i].ToString();
Console.WriteLine("Key: {0} Value: {1}",
key, appSettings[key]);
i += 1;
}
Console.WriteLine();
}
Last edited by FishGuy; Sep 22nd, 2010 at 03:05 AM.
-
Sep 21st, 2010, 08:13 PM
#2
Re: Storing Groups of Values in the App.Config and reading the values
Is this a Windows app or a Web app?
-
Sep 22nd, 2010, 03:04 AM
#3
Thread Starter
Frenzied Member
Re: Storing Groups of Values in the App.Config and reading the values
It is actually a VSTO app so I suppose it compares most likely to a Windows app.
-
Sep 22nd, 2010, 04:42 AM
#4
Re: Storing Groups of Values in the App.Config and reading the values
The reason I asked is that you are using the WebConfigurationManager class to read the config file. If it's not a web app then you should be using the ConfigurationManager class.
I assume that you creating those settings on the Settings page of the project properties. I've never used VSTO so I don't know if that functionality is available but it looks like it from that config file. In that case you can create a setting of type StringCollection instead of type String. Again, assuming that VSTO supports it, you should be able to get your settings directly from Properties.Settings.Default rather than using ConfigurationManager at all.
-
Sep 22nd, 2010, 11:06 AM
#5
Thread Starter
Frenzied Member
Re: Storing Groups of Values in the App.Config and reading the values
I couldnt find StringCollection on the properties settings so must assume it is not possible, instead I will create an array in a public class and store my values there instead.
-
Sep 22nd, 2010, 05:51 PM
#6
Re: [RESOLVED] Storing Groups of Values in the App.Config and reading the values
Are you sure it's not there? Maybe it's not but note that, for other projects, it's listed with it's fully-qualified name, i.e. System.Collections.Specialized.StringCollection.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|