Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Write values in app.config file

Tags:

c#

can anyone please help me how can I set/store values in the app.config file using c#, is it possible at all?

like image 676
Rana Avatar asked Jan 21 '11 12:01

Rana


People also ask

How read and write config file in C#?

The easiest way to read/write AppSettings config file there is a special section in reserved which allows you to do exactly that. Simply add an <appsettings> section and add your data as key/value pairs of the form <add key="xxx" value="xxxx" /> . That's all to create a new app. config file with settings in it.

How read app config file in C# Windows application?

Add the App. config file to your project. After creating a . NET Framework project, right-click on your project in Solution Explorer and choose Add > New Item. Choose the Application Configuration File item and then select Add.


1 Answers

Try the following code:

    Configuration config = ConfigurationManager.OpenExeConfiguration(Application.ExecutablePath);     config.AppSettings.Settings.Add("YourKey", "YourValue");     config.Save(ConfigurationSaveMode.Minimal); 

It worked for me :-)

like image 145
Amol M Kulkarni Avatar answered Sep 20 '22 04:09

Amol M Kulkarni