views:

414

answers:

4

Hi

I have build a C# program.

I need to keep setting of my program and I need to load them when the program load

(I know to do it with simple text file....but i don't have good documentation of the variable)

what is the best way to do it ?

Can I get any sample ?

+4  A: 

Use appSettings (that's the MSDN link, here's more of a quick overview).

Vinay Sajip
A: 

How about storing the settings in XML?

Reading and writing them is pretty easy.

kkaploon
A: 

In your solution, if you right click on the project and click on properties, there's a settings tab. You can define the settings you want to track and their types there and then access them through code, like this:

Properties.Settings.Default.SettingName = "Test Value";
Properties.Settings.Default.Save();

And then on load:

textBox.Text = Properties.Settings.Default.SettingName;
jasonh
+2  A: 

I'd argue that just hinting towards appSettings doesn't really cover the topic, as there is more advanced and eventually easier to use stuff readily available. Given that this question might be a

Duplicate

Best way to save per user options in C#

Please note that the MSDN link provided there (User settings in C#) covers both user and application scoped settings on an easy to grasp introductory level and basically elaborates on the correct example provided by jasonh already.

For a much deeper coverage of these topics (assuming you are using Windows Forms or WPF with Visual Studio) I'd recommend to look into Application Settings for Windows Forms.

Steffen Opel