writing to app.comfig file

G

Guest

Hello Everyone,

I am trying to read and write another application app.config file. I am
trying to follow this code that i got from internet

xeConfigurationFileMap fileMap = new ExeConfigurationFileMap();
fileMap.ExeConfigFilename = @"C:/app1.exe.config";
// relative path names possible

// Open another config file
Configuration config
=ConfigurationManager.OpenMappedExeConfiguration(fileMap,ConfigurationUserLevel.None);

//read/write from it as usual
ConfigurationSection mySection = config.GetSection("appSettings");


when I come to this line, I can access my code by the code below

((System.Configuration.AppSettingsSection)(mySection)).InternalSettings.AllKeys[0]

The value returned by above command is connectionString. I want to change
the value of the connection string and save the file.

How can I acheive this with the code above or if someone has any other ideas
of writing to a config file.


config.Save(ConfigurationSaveMode.Full); // Save changes


Below is my config file

<appSettings>

<add key="connectionString" value =
"Server=appoa1;uid=sa;pwd=sa;Database=CAT;" />
</appSettings>

Any help will be greatly apprecaited.

Thanks.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top