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.
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.