Link to home
Start Free TrialLog in
Avatar of bman9111
bman9111

asked on

c# configuration file

I have a c# program that I want to store configurations in a file and have my program read it. What would a coding look like for something like this?
Avatar of joechina
joechina

Which version of .net are you using?

Here is a simple example:
// C#
NameValueCollection AllAppSettings = ConfigurationManager.AppSettings;
Console.WriteLine(AllAppSettings["ApplicationName"]);

Put the following in your App.Config file
<appSettings>
<add key="ApplicationName" value="Demo Application"/>
<add key="ApplicationVersion" value="2.0.0.1"/>
<add key="UserFirstName" value="John"/>
<add key="UserLastName" value="Public"/>
</appSettings>

More detail please see System.configuration namespace

http://msdn2.microsoft.com/en-us/library/system.configuration.configurationmanager.aspx

The other option is to use new project settings feature in VS2005. (VS generates a set of class to manage settings)
Example
http://www.codeproject.com/vb/net/appsettings2005.asp
Avatar of bman9111

ASKER

I am using 2005.

Please explain how I can do this. What I want is a stand alone file that is in the same directory as the exe so that I could go into and change the settings versus having to go into the code and recompile.

ASKER CERTIFIED SOLUTION
Avatar of joechina
joechina

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial