問題:值由用戶在初始啓動設置將不會留在App.config中XML無法獲得App.config中設置堅持
所需的功能:值由用戶設定爲保持存儲在應用程序.config,除非用戶更改
我想使它第一次由用戶運行應用程序,他們設置一個文件夾,他們與程序所做的文件將被保存。我想將該字符串存儲在App.config中,以便只需設置一次。現在,它將設置它並將其保存在內存中,但如果程序關閉,則該值將丟失。我認爲調用.save()方法會修復它,但它沒有。 在模子開口:
if (ConfigurationManager.AppSettings["SaveFilePath"] == null)
{
FolderBrowserDialog fbd1 = new FolderBrowserDialog();
fbd1.RootFolder = Environment.SpecialFolder.MyComputer;
fbd1.Description = "Select a folder to save to:";
fbd1.ShowNewFolderButton = true;
if (fbd1.ShowDialog() == DialogResult.OK)
{
Configuration config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
config.AppSettings.Settings.Add("SaveFilePath", fbd1.SelectedPath);
config.Save();
ConfigurationManager.RefreshSection("appSettings");
}
}
App.Config中不打算成爲持久的存儲解決方案。你應該考慮以另一種方式堅持這些選項,或許是一個settings.json? – maccettura