Results 1 to 6 of 6

Thread: [RESOLVED] Storing Groups of Values in the App.Config and reading the values

Threaded View

  1. #1

    Thread Starter
    Frenzied Member FishGuy's Avatar
    Join Date
    Mar 2005
    Location
    Bradford UK
    Posts
    1,708

    Resolved [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.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width