Ext.Net 1.X_读写配置文件
来源:互联网 发布:找数据网站有哪些 编辑:程序博客网 时间:2024/06/01 07:45
[摘要]
有N个ERP数据库帐套,需要从XML文件中读取。
加载指定路径的XML
/// <summary> /// 取得帐套列表 /// </summary> private void GetDBList() { List<object> data = new List<object>(); XmlDocument xmlDoc = new XmlDocument(); xmlDoc.Load(@"d:\db.xml"); XmlNode xn = xmlDoc.SelectSingleNode("Mydatabase"); XmlNodeList xnl = xn.ChildNodes; string company = string.Empty; string connectstring=string.Empty; foreach (XmlNode xnf in xnl) { XmlElement xe = (XmlElement)xnf; company = xe.GetAttribute("dispalyname"); connectstring = string.Format("Server={0};Database={1};uid={2};pwd={3}", xe.GetAttribute("Server"), xe.GetAttribute("Database"), xe.GetAttribute("uid"), xe.GetAttribute("pwd")); data.Add(new { name = company, connectstring = connectstring }); } this.DataBaseStore.DataSource = data; this.DataBaseStore.DataBind(); this.cbxDb.SelectedIndex = 0; }
用户选择帐套修改.config
/// <summary> /// 确认帐套修改配置文件连接字符串 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> protected void Login_Click(object sender, DirectEventArgs e) { if (cbxDb.SelectedItem.Value.ToString() != "") { BaseConfig bc = new BaseConfig("Config/CurrentConnect.config"); bc.SaveConfig(this.cbxDb.SelectedItem.Value.Trim(),"ConnectString"); Response.Redirect("Index.aspx"); } else { X.Msg.Alert("提示","请选择帐套").Show(); } }
/// <summary> /// 写入配置文件 key value /// </summary> /// <param name="ConnenctionString"></param> /// <param name="strKey"></param> public void SaveConfig(string ConnenctionString, string strKey) { XmlDocument doc = new XmlDocument(); //获得配置文件的全路径 string strFileName = HttpContext.Current.Server.MapPath(configPath); doc.Load(strFileName); //找出名称为“add”的所有元素 XmlNodeList nodes = doc.GetElementsByTagName("add"); for (int i = 0; i < nodes.Count; i++) { //获得将当前元素的key属性 XmlAttribute att = nodes[i].Attributes["key"]; //根据元素的第一个属性来判断当前的元素是不是目标元素 if (att.Value == strKey) { //对目标元素中的第二个属性赋值 att = nodes[i].Attributes["value"]; att.Value = ConnenctionString; break; } } //保存上面的修改 doc.Save(strFileName); } /// <summary> /// 读取配置文件key-value值 /// </summary> /// <param name="ConnenctionString"></param> /// <param name="strKey"></param> public string GetConfigKeyValue(string strKey) { XmlDocument doc = new XmlDocument(); string ConnectString = string.Empty; doc.Load(HttpContext.Current.Server.MapPath(configPath)); //找出名称为“add”的所有元素 XmlNodeList nodes = doc.GetElementsByTagName("add"); for (int i = 0; i < nodes.Count; i++) { //获得将当前元素的key属性 XmlAttribute att = nodes[i].Attributes["key"]; if (att.Value == strKey) { ConnectString = nodes[i].Attributes["value"].Value.ToString(); } } return ConnectString; }
- Ext.Net 1.X_读写配置文件
- .net读写配置文件
- 关于.NET 2.0 配置文件读写
- VB.NET读写INI配置文件
- asp.net 2.0 读写配置文件
- asp.net 2.0 读写配置文件
- asp.net 2.0 读写配置文件
- .net exe 程序读写配置文件
- asp.net 2.0 读写配置文件
- VB.NET读写INI配置文件
- .net 2.0 中对配置文件的读写
- .NET 2.0中,使用ConfigureManager读写配置文件
- ASP.NET 使用ConfigurationManager读写配置文件
- .net 2.0 中对配置文件的读写
- .net 2.0 中对配置文件的读写
- .Net 2.0 中配置文件的读写(转)
- asp.net 读写配置文件Web.Config
- asp.net 读写配置文件Web.Config
- 两台服务器之间建立dblink的SQL写法
- 编译环境搭建:Makefile
- nyist 202 红黑树(二叉树中序遍历)
- SpringMVC接收页面表单参数
- Java 泛型学习笔记(一)
- Ext.Net 1.X_读写配置文件
- Java 泛型学习笔记(二)
- S3-客户端API测试
- WPF的DataGrid如何让列自动填充 犀利快捷
- linux screen 命令详解
- 处理SQLServer数据库孤立用户的解决方案
- VLFeat开源库入门
- 【win7死机解决自动生成错误文件的设置方法】
- 【美化§绿色爱心的树xp电脑主题下载§】