I am trying to save a custom section in my app.config. This is the code that I still have:
Configuration configuration = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None); //Read the TunnelSection from the configuration file TunnelSection tunnels = ConfigurationManager.GetSection("TunnelSection") as TunnelSection; HostConfigElement newhost = new HostConfigElement(); newhost.Password = "hola"; newhost.SSHPort = 22; newhost.SSHServerHostname = "holahola"; TunnelConfigElement newtunnel = new TunnelConfigElement(); newtunnel.LocalPort = 12; newtunnel.RemotePort = 12; newtunnel.Name = "12"; newtunnel.DestinationServer = "12"; TunnelCollection newtunnelcollection = new TunnelCollection(); newtunnelcollection.Add(newtunnel); newhost.Tunnels = newtunnelcollection; tunnels.Tunnels.Add(newhost); ConfigurationManager.RefreshSection("TunnelSection"); configuration.Save(ConfigurationSaveMode.Full);
The problem is that the configuration file does not change. If I go through TunnelSection, I see that a new host has been added.
To eliminate permission issues, I tried adding a parameter to appsettings as follows:
configuration.AppSettings.Settings.Add("hola", "hola");
and it works great.
I also tried saveas, but to no avail.
Any ideas? TIA
source share