Can someone please help me. i am making a windows form that will change the app.config file values that the user enters in the textbox through the form.
iam using an external connection string.which is my connection string is inside the app.config file.
i want to change the machine_name, database_name, id, and password entered from the form and save it.or modify it.
my app.config file is:
please help me.
Jignesh TrivediPosted Mar 14, 2013, 1:04 AM
hi,
you have two way to update Config file.
1) use ConfigurationManager to update App.config.
Configuration config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
config.ConnectionStrings.ConnectionStrings.Remove("Test");
config.ConnectionStrings.ConnectionStrings.Add(new ConnectionStringSettings { Name = "Test", ConnectionString = "Data Source=local;Initial Catalog=Phase2;User ID=devuser;Password=password;MultipleActiveResultSets=True" });
config.Save(ConfigurationSaveMode.Full);
ConfigurationManager.RefreshSection("connectionStrings");
2) config file is generally XML file so that you can load it as XML file and update node.
Please refer
http://www.c-sharpcorner.com/UploadFile/1a81c5/configuring-connection-string-in-app-config-file-during-runt/
hope this will help you.