RE: APP.CONFIG by dbgrick
dbgrick
Tue Oct 02 05:24:02 PDT 2007
Here is a home grown C# version you can use:
/// <summary>
/// Configuration Settings class. Mimics the Microsoft Configuration
settings class
/// </summary>
public static class ConfigurationSettings
{
#region Public Properties
public static NameValueCollection AppSettings;
#endregion
#region Constructor
/// <summary>
/// Static constructor. Loads configuratio settings
/// </summary>
static ConfigurationSettings()
{
}
#endregion
#region Private Static Methods
/// <summary>
/// Loads configuratio settings from file
/// </summary>
/// <exception cref="ArgumentException">Thrown if the configuration
file does not exist</exception>
public static void LoadConfig()
{
try
{
//Gets the directory name
string ConfigFile = string.Format("{0}.config",
Assembly.GetCallingAssembly().GetName().CodeBase);
// Notify user of missing config file
if (File.Exists(ConfigFile) == false)
{
throw new ArgumentException("Configuration File Does not
Exist");
}
// Xml document to parse config file
XmlDocument oXml = new XmlDocument();
// Load the file
oXml.Load(ConfigFile);
// Get the appsettings xpath
XmlNodeList oList = oXml.GetElementsByTagName("appSettings");
// Create the name value pair collection
AppSettings = new NameValueCollection();
// Load all keys
foreach (XmlNode oNode in oList)
{
foreach (XmlNode oKey in oNode.ChildNodes)
{
AppSettings.Add(oKey.Attributes["key"].Value,
oKey.Attributes["value"].Value);
}
}
}
catch (Exception) { throw; }
}
#endregion
}
Regards,
Rick D.
Contractor
"Fatih" wrote:
> In WM5, is there anything similar to app.config that we use on desktop
> environment?
>
>