Util - Add Method AddOrUpdateAppSettings
This commit is contained in:
parent
9d25ac394b
commit
73e353b99e
|
@ -1,5 +1,6 @@
|
|||
using Newtonsoft.Json;
|
||||
using System;
|
||||
using System.Configuration;
|
||||
using System.Diagnostics;
|
||||
using System.Drawing;
|
||||
using System.IO;
|
||||
|
@ -174,6 +175,29 @@ namespace AIParkingApplication
|
|||
hostName = hostParts[0];
|
||||
int.TryParse(hostParts[1], out port);
|
||||
}
|
||||
|
||||
public static void AddOrUpdateAppSettings(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");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public class PlateRequestEngineModel
|
||||
|
|
Loading…
Reference in New Issue
Block a user