使用ExeConfigurationFileMap讀寫配置文件
来源:互联网 发布:安卓自带应用源码 编辑:程序博客网 时间:2024/06/10 10:34
http://www.cnblogs.com/anjou/archive/2011/06/02/2068504.html
using System;using System.IO;using System.Configuration;public class AppConfig{ public string LastLoginId { get { return this.GetItem("LastLoginId"); } set { this.SetItem("LastLoginId", value); } } private Configuration config; public AppConfig() { ExeConfigurationFileMap configMap = new ExeConfigurationFileMap(); configMap.ExeConfigFilename = this.CreateConfig(); this.config = ConfigurationManager.OpenMappedExeConfiguration(configMap, ConfigurationUserLevel.None); } private string CreateConfig() { try { string configFile = AppDomain.CurrentDomain.BaseDirectory + @"app.config"; if (!File.Exists(configFile)) { string xml = "<?xml version=\"1.0\" encoding=\"utf-8\" ?>\r\n<configuration>\r\n</configuration>"; using (StreamWriter sw = new StreamWriter(configFile)) { sw.Write(xml); } } return configFile; } catch (Exception ex) { string msg = ex.Message; throw; } } private string GetItem(string item) { if (this.config.AppSettings.Settings[item] == null) { return string.Empty; } else { return this.config.AppSettings.Settings[item].Value; } } private void SetItem(string item, string value) { if (this.config.AppSettings.Settings[item] == null) { this.config.AppSettings.Settings.Add(item, value); } else { this.config.AppSettings.Settings[item].Value = value; } this.Save(); } private void Save() { try { this.config.Save(ConfigurationSaveMode.Modified); } catch (Exception ex) { string msg = ex.Message; throw; } }}
- 使用ExeConfigurationFileMap讀寫配置文件
- 配置文件使用
- 如何使用.NET配置文件
- 使用Java的配置文件
- 配置文件的使用
- 如何使用.NET配置文件
- 使用WindowsAPI读写配置文件
- 如何使用.NET配置文件
- 使用.NET配置文件
- 配置文件的使用
- 4.3.3 使用配置文件
- 使用 sed 修改配置文件
- 配置文件的使用
- 使用 rapidxml 做配置文件
- 配置文件properties的使用
- Spring 使用Properties配置文件
- 使用客户机自动配置文件
- 无配置文件使用log4j
- dp hdu-4433 locker
- Block Objects 学习笔记
- MFC实现拖拽文件
- C#初学者--用类打开mdb文件
- hdu 1011 Starship Troopers (树形背包dp)
- 使用ExeConfigurationFileMap讀寫配置文件
- Qt控件美化
- Json解析与NDK入门
- web.xml中的contextConfigLocation的作用
- openCV矩阵和图像类型
- Zlib编程详解
- 获取普通用户 iOS 装置上的 Crash Log 的方法
- 在DLL中使用ADO连接数据库的问题
- Oracle 生成随机密码