我正在讀取和寫入用戶設置的app.config文件。我找到了一個用於處理confige文件的代碼片段。我終於獲得了它的編譯和運行,但它似乎完全沒有對App.config文件做任何事情。在app.config文件中寫入/讀取用戶定義的設置
下面是代碼:
Method MainForm1.Button1.Click(sender: System.Object; e: System.EventArgs);
var
config : System.Configuration.Configuration;
begin
config:=ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
config.AppSettings.Settings.Add('PreferenceToRemember','value1');
config.Save(ConfigurationSaveMode.Modified);
ConfigurationManager.RefreshSection('appSettings');
end;
它沒有任何錯誤的編譯,但我不知道這是否是做任何事情。
代碼有問題嗎?我需要能夠寫/讀一個部分並寫/讀一個鍵/值。提前致謝。
更新:而不是使用ConfigurationManager,我只是使用Properties.Settings.Default。然而,儘管程序沒有任何錯誤並且代碼看起來很簡單,但我仍然有一些問題需要寫入並從中讀回。
如何從代碼中讀寫Properties.Settings.Default?
看到這個堆棧溢出的答案: http://stackoverflow.com/questions/1157378/unable-to-save-settings-in-app-exe-config –