I have the following VB code that works fine, I need this ti be conveeted to C#, but it seems C' does things differently.
If chkGoingFlying.Checked Then
Config.AppSettings.Settings.Item("GoingFlying").Value = 1
Else
Config.AppSettings.Settings.Item("GoingFlying").Value = 0
End If
Config.Save()
This is a web application and I have a reference at the top - Private Config As Configuration.
From searching I'm confused whether to use CongigurationManager or WebConfigurationManager. Neither works.
Is anyone able to help.
Andy
configFile.Save(ConfigurationSaveMode.Modified);
static void AddUpdateAppSettings(string key, string value)
{
try
{
var configFile = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
var settings = configFile.AppSettings.Settings;
if (settings[key] == null)
{
settings.Add(key, value);
}
else
{
settings[key].Value = value;
}
configFile.Save(ConfigurationSaveMode.Modified);
ConfigurationManager.RefreshSection(configFile.AppSettings.SectionInformation.Name);
}
catch (ConfigurationErrorsException)
{
Console.WriteLine("Error writing app settings");
}
}
Share your converted c# code if you need any further assistance