How do I modify the web.config of a web site during the setup's execution? I would like to have the user construct a connection string and then store that in the web config.
+1
A:
This link (How To Modify Web.Config At Run Time) gives some insight.
Jeremy Cron
2009-09-03 19:21:46
I don't know how to access to the web site/application folder from the setup project I am in.
Irwin
2009-09-03 19:32:41
A:
I have found this to work. But this at run time not set up.
public void ChangeAppSettings(string applicationSettingsName, string newValue)
{
Configuration config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
KeyValueConfigurationElement element = config.AppSettings.Settings[applicationSettingsName];
if (element == null)
{
config.AppSettings.Settings.Add(applicationSettingsName, newValue);
}
else
{
element.Value = newValue;
}
config.Save(ConfigurationSaveMode.Modified, true);
ConfigurationManager.RefreshSection("appSettings");
}
David Basarab
2009-09-04 19:58:56