config.xml写入和读取
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Xml;
namespace ZhuoHuiSchoolRoom.ZhuoHuiClass
{
class Global
{
/// <summary>
/// 获取xml文件中的值
/// </summary>
/// <param name="xmlValues">键</param>
/// <returns></returns>
public static string getValues(string name)
{
XmlDocument xml = new XmlDocument();
//读取xml文件
xml.Load(System.Environment.CurrentDirectory + "\\config.xml");
foreach (XmlNode node in xml.ChildNodes)
{
if (node.Name == "SettingsFile")
{
foreach (XmlNode node1 in node.ChildNodes)
{
if (node1.Name == name)
{
foreach (XmlNode node2 in node1.ChildNodes)
{
if (node2.Name == "Value")
{
return node2.InnerText;
}
}
}
}
}
}
return "";
}
/// <summary>
/// 数据写入config.xml
/// </summary>
/// <param name="name">键</param>
/// <param name="values">值</param>
public static void setValues(string name, string values)
{
XmlDocument xml = new XmlDocument();
xml.Load(System.Environment.CurrentDirectory + "\\config.xml"); //获取xml文件路径
XmlNode XN = xml.SelectSingleNode("SettingsFile");
XN = XN.SelectSingleNode(name);
XN.SelectSingleNode("Value").InnerText = values;
xml.Save(System.Environment.CurrentDirectory + "\\config.xml");
}
public static string getIPValues()
{
XmlDocument doc = new XmlDocument();
doc.Load(System.Environment.CurrentDirectory + "\\ZhuoHuiSchoolroom.exe.config");
string IP = ((System.Xml.XmlNode)(doc)).InnerText;
return IP;
//XmlDocument xml = new XmlDocument();
////读取xml文件
//xml.Load(System.Environment.CurrentDirectory + "\\ZhuoHuiSchoolroom.exe.config");
//foreach (XmlNode node in xml.ChildNodes)
//{
// if (node.Name == "configuration")
// {
// foreach (XmlNode node1 in node.ChildNodes)
// {
// if (node1.Name == "applicationSettings")
// {
// foreach (XmlNode node2 in node1.ChildNodes)
// {
// if (node2.Name == "ZhuoHuiSchoolroom.Properties.Settings")
// {
// foreach (XmlNode node3 in node2.ChildNodes)
// {
// if (node3.Name == "setting")
// {
// foreach (XmlNode node4 in node3.ChildNodes)
// {
// if (node4.Name == "value")
// {
// return node3.InnerText;
// }
// }
// }
// }
// }
// }
// }
// }
// }
//}
}
}
}
config.xml文件内容示例
<?xml version="1.0" encoding="utf-8"?>
<SettingsFile>
<Width>
<Value>1024</Value>
</Width>
<Height>
<Value>768</Value>
</Height>
</SettingsFile>
写入
Global.setValues("Width", this.Width.ToString());
Global.setValues("Height", this.Height.ToString());
读取
string width = Global.getValues("Width");
string height = Global.getValues("Height");
config.xml写入和读取的更多相关文章
- ASP.NET写入和读取xml文件
xml是一种可扩展标记语言,在电子计算机中,标记指计算机所能理解的信息符号,通过此种标记,计算机之间可以处理包含各种的信息比如文章等.它可以用来标记数据.定义数据类型,是一种允许用户对自己的标记语言进 ...
- 在C#程序中,创建、写入、读取XML文件的方法
一.在C#程序中,创建.写入.读取XML文件的方法 1.创建和读取XML文件的方法,Values为需要写入的值 private void WriteXML(string Values) { //保存的 ...
- XML数据的读取—数据库配置文件
数据库配置文件(config.xml) <?xml version="1.0" encoding="utf-8"?> <configurati ...
- [xml解析]rapidxml读取文件
因为项目需要读取xml配置文件,在原来调查一番后,项目组使用了tinyxml. tinyxml确实简单,非常清楚的就把读取方案写出来了.但是,由于后期xml文件越来越大(2.5M,大概1w多行数据), ...
- php 如何写入、读取word,excel文档
如何在php写入.读取word文档 <? //如何在php写入.读取word文档 // 建立一个指向新COM组件的索引 $word = new COM("word.applicatio ...
- 在Linux下如何用Shell脚本读写XML?现有一个config.xml(转)
在Linux下如何用Shell脚本读写XML?现有一个config.xml <?xml version="1.0" encoding="UTF-8"?&g ...
- spring 框架的xml文件如何读取properties文件数据
spring 框架的xml文件如何读取properties文件数据 第一步:在spring配置文件中 注意:value可以多配置几个properties文件 <bean id="pro ...
- WinForm中DataGridView对XML文件的读取
转自http://www.cnblogs.com/a1656344531/archive/2012/11/28/2792863.html c#读取XML XML文件是一种常用的文件格式,例如Win ...
- 如何写入和读取从 Microsoft 消息队列在 Visual C#
注意:这篇文章是由无人工介入的微软自动的机器翻译软件翻译完成.微软很高兴能同时提供给您由人工翻译的和由机器翻译的文章, 以使您能使用您的语言访问所有的知识库文章.然而由机器翻译的文章并不总是完美的.它 ...
随机推荐
- [C#] Parallel.For的线程数
Parallel.For会自动判断同时运行多少个线程,但你也可以进行干预. ParallelOptions可以设置Parallel.For最大的并发线程.缺省的最大线程数是CPU核数.这通常是不够多的 ...
- hdu 1708 Fibonacci String
Fibonacci String Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Tot ...
- window10+python3.7安装tensorflow--gpu tensorflow 安装
能安装GPU的前提是:1.显卡支持CUDA (1)右击我的电脑–属性 (2)打开设备管理器 (3)显示适配器 我的电脑是支持CUDA的 2.pip 版本 >= 8.1查看pip版本 :pip ...
- 机器学习-RBF高斯核函数处理
机器学习-RBF高斯核函数处理 SVM高斯核函数-RBF优化 重要了解数学的部分: 协方差矩阵,高斯核函数公式. 个人建议具体的求法还是看下面的核心代码吧,更好理解,反正就我个人而言,烦躁的公式,还 ...
- HDU 1850 Nim-Sum思想总结、
算法介绍: Nim游戏是指两个对手在m个堆中轮流随意从某一个堆中拿出n个元素,假定两个对手都是足够聪明,直至最后一次取的人将所有元素取出,此人取得胜利.与之相反的是Misere游戏,相同的游戏规则,但 ...
- 2019-1-29-C#-Task.Run-和-Task.Factory.StartNew-区别
title author date CreateTime categories C# Task.Run 和 Task.Factory.StartNew 区别 lindexi 2019-01-29 16 ...
- Python--day38---进程间通信--初识队列(multiprocess.Queue)之生产者,消费者模型
1,生产者消费者模型.py import random import time from multiprocessing import Queue, Process def producer(name ...
- gulp 批量添加类名 在一个任务中使用多个文件来源
1.首先安装环境 1.安装gulp: npm install gulp 2.安装gulp-clean-css npm install gulp-clean-css 3.安装gulp-css-wrap ...
- LuoguP3521 [POI2011]ROT-Tree Rotations
P3521 [POI2011]ROT-Tree Rotations 题目大意: 给一棵\((1≤n≤200000)\)个叶子的二叉树,可以交换每个点的左右子树,要求前序遍历叶子的逆序对最少. 我们发现 ...
- Sql Server知识点拨
一.Sql Server异常捕获try catch 二.集增加与修改的存储过程 三.显示某一列中有重复值的行 转载自:https://www.cnblogs.com/527289276qq/