For programmatic access to .NET *.config files : AppSettingsReader « Development « C# / CSharp Tutorial






using System;
using System.Configuration;

class MainClass
{
  static void Main(string[] args)
  {
    AppSettingsReader ar = new AppSettingsReader();
    Console.WriteLine("Here is your conn string");
    Console.WriteLine(ar.GetValue("appConStr", typeof(string)));
    Console.WriteLine();
    int numbOfTimes = (int)ar.GetValue("intValue", typeof(int));
    for(int i = 0; i < numbOfTimes; i++)
      Console.WriteLine("Yo!");
  }
}
/*
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
  <appSettings>
    <add key="appConStr" value="server=localhost;uid=sa;pwd=;database=Cars" />
    <add key="intValue" value="4" />
  </appSettings>
</configuration>
*/








14.12.AppSettingsReader
14.12.1.Use AppSettingsReader to load settings from app.config
14.12.2.For programmatic access to .NET *.config files
14.12.3.Store ConnectionStringConfig solution