Ext.Net 1.X_读写配置文件
[摘要]
有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_读写配置文件的更多相关文章
- 用ConfigParser模块读写配置文件——Python
对于功能较多.考虑用户体验的程序,配置功能是必不可少的,如何存储程序的各种配置? 1)可以用全局变量,不过全局变量具有易失性,程序崩溃或者关闭之后配置就没了,再者配置太多,将变量分配到哪里也是需要考虑 ...
- 使用ConfigurationManager类读写配置文件
使用ConfigurationManager类 读写配置文件app.config,以下为代码: view plaincopy to clipboard print? using System; usi ...
- Python自动化测试 (二) ConfigParser模块读写配置文件
ConfigParser 是Python自带的模块, 用来读写配置文件, 用法及其简单. 直接上代码,不解释,不多说. 配置文件的格式是: []包含的叫section, section 下有op ...
- C读写配置文件
在项目开发中,经常需要读取应用配置文件的初始化参数,用于应用在启动前进行一些初始化配置.比如:Eclipse,参数项包含主题.字体大小.颜色.Jdk安装位置.自动提示等.Eclispe配置的文件格式是 ...
- Python自动化测试 -ConfigParser模块读写配置文件
C#之所以容易让人感兴趣,是因为安装完Visual Studio, 就可以很简单的直接写程序了,不需要做如何配置. 对新手来说,这是非常好的“初体验”, 会激发初学者的自信和兴趣. 而有些语言的开发环 ...
- python:实例化configparser模块读写配置文件
之前的博客介绍过利用python的configparser模块读写配置文件的基础用法,这篇博客,介绍下如何实例化,方便作为公共类调用. 实例化的好处有很多,既方便调用,又降低了脚本的维护成本,而且提高 ...
- python:利用configparser模块读写配置文件
在自动化测试过程中,为了提高脚本的可读性和降低维护成本,将一些通用信息写入配置文件,将重复使用的方法写成公共模块进行封装,使用时候直接调用即可. 这篇博客,介绍下python中利用configpars ...
- python-ConfigParser模块【读写配置文件】
对python 读写配置文件的具体方案的介绍 1,函数介绍 import configParser 如果Configparser无效将导入的configParser 的C小写 1.1.读取配置文件 - ...
- python 读写配置文件
使用python读写配置文件,写个demo测试一下. #!/usr/bin/env python import os import ConfigParser # 如果文件不存在,就穿件文件. if o ...
随机推荐
- Template基础
模板系统的介绍 你可能已经注意到我们在例子视图中返回文本的方式有点特别. 也就是说,HTML被直接硬编码在 Python代码之中. def current_datetime(request): now ...
- Openstack: change endpoint IP addresses after installation
Prerequisites You have a single node DevStack installation using mysql for the database that was wor ...
- Core Python Programming一书中关于深浅拷贝的错误
该书关于深浅拷贝的论述: 6.20. *Copying Python Objects and Shallow and Deep Copies "when shallow copies are ...
- SSH 之 Spring的源码(二)——Bean实例化
首先来看一段代码,看过上一节的朋友肯定对这段代码并不陌生.这一段代码诠释了Spring加载bean的完整过程,包括读取配置文件,扫描包,加载类,实例化bean,注入bean属性依赖. <span ...
- 使用C++将OpenCV中Mat的数据写入二进制文件,用Matlab读出
在使用OpenCV开发程序时,如果想查看矩阵数据,比较费劲,而matlab查看数据很方便,有一种方法,是matlab和c++混合编程,可以用matlab访问c++的内存,可惜我不会这种方式,所以我就把 ...
- [tornado]使用webscoket的使用总是403错误
使用的tornado版本为4.0+ 后台: PS D:\CodeHouse\tornado\websocket> python .\ws_app.py WARNING:tornado.acces ...
- Hadoop MapReduce工作原理
在学习Hadoop,慢慢的从使用到原理,逐层的深入吧 第一部分:MapReduce工作原理 MapReduce 角色 •Client :作业提交发起者. •JobTracker: 初始化作业,分配 ...
- 如何向android studio中导入第三方类库
下面分两种情况介绍一下如何导入第三方类库. 1.对于jar的类库,直接复制进libs目录,然后把jar复制进去,然后File->Project Structure,然后选中主module的名称, ...
- Android中三种计时器Timer、CountDownTimer、handler.postDelayed的使用
在android开发中,我们常常需要用到计时器,倒计时多少秒后再执行相应的功能,下面我就分别来讲讲这三种常用的计时的方法. 一.CountDownTimer 该类是个抽象类,如果要使用这个类中的方法, ...
- 18 Ui美化 剪切动画clip
输入0 - 10000 让图片根据数值显示部分图片 在工程文件的res/drawable/新建clip文件 <?xml version="1.0" encoding=&quo ...