ASP.NET中Config文件读写的示例分析-创新互联
                                            这篇文章主要介绍ASP.NET中Config文件读写的示例分析,文中介绍的非常详细,具有一定的参考价值,感兴趣的小伙伴们一定要看完!

方法如下:
如果是WinForm程序,需要添加引用:
- System.ServiceModel 
- System.Configuration 
App.config
NetUtilityLib
using System.Configuration;
namespace pcauto
{
 public static class ConfigHelper
 { 
  ///  
  ///返回*.exe.config文件中appSettings配置节的value项  
  ///   
  ///  
  ///  
  ///在*.exe.config文件中appSettings配置节增加一对键值对  
  ///  
  /// 
  /// 
  public static void UpdateAppConfig(string newKey, string newValue) { 
   string file = System.Windows.Forms.Application.ExecutablePath;
   Configuration config = ConfigurationManager.OpenExeConfiguration(file); 
   bool exist = false; 
   foreach (string key in config.AppSettings.Settings.AllKeys) { 
    if (key == newKey) { exist = true; } 
   } 
   if (exist) { config.AppSettings.Settings.Remove(newKey); }
   config.AppSettings.Settings.Add(newKey, newValue); 
   config.Save(ConfigurationSaveMode.Modified);
   ConfigurationManager.RefreshSection("appSettings");
  }  
 }
}读示例
ConfigHelper.GetAppConfig("testkey")写示例
ConfigHelper.UpdateAppConfig("testkey", "abc");以上是“ASP.NET中Config文件读写的示例分析”这篇文章的所有内容,感谢各位的阅读!希望分享的内容对大家有帮助,更多相关知识,欢迎关注创新互联行业资讯频道!
分享标题:ASP.NET中Config文件读写的示例分析-创新互联
网站URL:http://www.scyingshan.cn/article/dcjgod.html

 建站
建站
 咨询
咨询 售后
售后
 建站咨询
建站咨询 
 