[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

c# configuration file

Posted on 2006-10-24
3
Medium Priority
?
293 Views
Last Modified: 2008-02-01
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?
0
Comment
Question by:bman9111
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 13

Expert Comment

by:joechina
ID: 17797089
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
0
 
LVL 8

Author Comment

by:bman9111
ID: 17797272
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.

0
 
LVL 13

Accepted Solution

by:
joechina earned 1000 total points
ID: 17797655
Right click your project and click Add --> new item...
From the list, select Application Configuration File.
Now you will have a App.config file in your project. Open it, and add
<appSettings>
     <add key="YourKey" value="Your Key Value"/>
</appSettings>
With <configuration> item.

Right click references in your project and click Add reference,
select System.configuration from the .NET page.

In you code, add
using System.Configuration;

Now in the code, you can use

ConfigurationManager.AppSettings["YourKey"] to get the value "Your Key Value".

Good Luck
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Extention Methods in C# 3.0 by Ivo Stoykov C# 3.0 offers extension methods. They allow extending existing classes without changing the class's source code or relying on inheritance. These are static methods invoked as instance method. This…
Article by: Ivo
C# And Nullable Types Since 2.0 C# has Nullable(T) Generic Structure. The idea behind is to allow value type objects to have null values just like reference types have. This concerns scenarios where not all data sources have values (like a databa…
This course is ideal for IT System Administrators working with VMware vSphere and its associated products in their company infrastructure. This course teaches you how to install and maintain this virtualization technology to store data, prevent vuln…
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…
Suggested Courses

649 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question