Sarevok
October 12th, 2005, 10:30 PM
Greetings,
I am currently developing a program that reads parameters from a configuration file. I need the configuration file to be in an xml format but I also need it to be editable by the user. I tried using the App.conf file but found out that it doesn't work when the App.conf file is renamed. Anybody know where to change the settings so that the program will work even if I rename the App.conf file?
Here's the code that I used
using System;
using System.Configuration;
public class Conf
{
public static string GetAppSetting(string key)
{
return (ConfigurationSettings.AppSettings[key] != null)
? ConfigurationSettings.AppSettings[key]
: string.Empty;
}
public static void Main()
{
string name;
string age;
string email;
name = GetAppSetting("name");
age = GetAppSetting("AGE");
Console.WriteLine(name);
Console.WriteLine(age);
Console.ReadLine();
}
}
and this is the App.conf file
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<appSettings>
<add key="temp" value="5.0" />
<add key="Name" value="Roland" />
<add key="Age" value="21" />
<add key="Address" value="Cebu" />
<add key="Email" value="me@me.com"/>
</appSettings>
</configuration>
thanks
I am currently developing a program that reads parameters from a configuration file. I need the configuration file to be in an xml format but I also need it to be editable by the user. I tried using the App.conf file but found out that it doesn't work when the App.conf file is renamed. Anybody know where to change the settings so that the program will work even if I rename the App.conf file?
Here's the code that I used
using System;
using System.Configuration;
public class Conf
{
public static string GetAppSetting(string key)
{
return (ConfigurationSettings.AppSettings[key] != null)
? ConfigurationSettings.AppSettings[key]
: string.Empty;
}
public static void Main()
{
string name;
string age;
string email;
name = GetAppSetting("name");
age = GetAppSetting("AGE");
Console.WriteLine(name);
Console.WriteLine(age);
Console.ReadLine();
}
}
and this is the App.conf file
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<appSettings>
<add key="temp" value="5.0" />
<add key="Name" value="Roland" />
<add key="Age" value="21" />
<add key="Address" value="Cebu" />
<add key="Email" value="me@me.com"/>
</appSettings>
</configuration>
thanks