統計資訊
  • 文章數 - 72
  • 回應數 - 4
  • 引用數 - 0

 

讀寫 應用程式設定檔 xxx.exe.config

//先加入參考System.Configuration
//再using
using System.Configuration;
        //寫入設定檔
        protected void SetAppSettings(String key, String value)
        {
            Configuration oConfig = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
 
            if (ConfigurationManager.AppSettings[key] != null)
                oConfig.AppSettings.Settings[key].Value = value;
            else
                oConfig.AppSettings.Settings.Add(key, value);
 
            oConfig.Save(ConfigurationSaveMode.Modified);
 
            ConfigurationManager.RefreshSection("appSettings");
        }
        //讀取設定檔
        protected String GetAppSettings(String key, String defaultValue)
        {
            if (ConfigurationManager.AppSettings[key] == null) SetAppSettings(key, defaultValue);
            return ConfigurationManager.AppSettings[key];
        }
//使用
//寫入
SetAppSettings("txtAccount",txtAccount.Text);
//讀取
txtAccount.Text = GetAppSettings("txtAccount", "");



回應

目前沒有回應.


回應




 


登入後使用進階評論

Please add 8 and 7 and type the answer here:

 

 

Copyright © Yang Hsuan-Ming