<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<configSections>
<sectionGroup name="applicationSettings" type="System.Configuration.ApplicationSettingsGroup, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" >
<section name="WebService测试程序.Properties.Settings" type="System.Configuration.ClientSettingsSection, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
</sectionGroup>
</configSections>
<applicationSettings>
<WebService测试程序.Properties.Settings>
<setting name="WebService测试程序_WebReference1_Service1" serializeAs="String">
<value>http://10.68.69.203:8081/TWS.asmx</value>
</setting>
<setting name="WebService测试程序_WebReference2_Service1" serializeAs="String">
<value>http://10.68.69.203:8082/TWS.asmx</value>
</setting>
</WebService测试程序.Properties.Settings>
</applicationSettings>
</configuration>
这就是xml文档的内容,是配置文件文件名为WebService测试程序.vshost.exe.config我的程序可以获取到那个value的值但是我修改之后没有改变值不知道是什么问题请高手指导一下 谢谢private void button1_Click(object sender, EventArgs e)
{
//string exeConfigFile = Process.GetCurrentProcess().MainModule.FileName + ".config";
//XmlDocument doc = new XmlDocument();
//doc.Load(exeConfigFile);
//XmlNodeList list = doc.DocumentElement.GetElementsByTagName("applicationSettings");
//foreach (XmlNode node in list)
//{
// MessageBox.Show(node.ChildNodes[0].ChildNodes[0].InnerText);
// node.ChildNodes[0].ChildNodes[0].InnerText = "aa";
// MessageBox.Show(node.ChildNodes[0].ChildNodes[0].InnerText);
//} XmlDocument doc = new XmlDocument();
//获得配置文件的全路径
string strFileName = AppDomain.CurrentDomain.SetupInformation.ConfigurationFile;
doc.Load(strFileName);
//找出名称为“add”的所有元素
XmlNodeList nodes = doc.GetElementsByTagName("setting");
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;
//}
for (int j = 0; j < nodes[i].ChildNodes.Count; j++)
{
if (i==0 && j==0)
{
nodes[i].ChildNodes[j].InnerText = "aa";
}
}
}
//保存上面的修改
doc.Save(strFileName);
}执行下来都没有问题 但是 内容我看了看 确实是没有修改不知道是什么问题。C#XMLconfig文件
解决方案 »
- C# 将页面所有内容导出到word
- C#中如何用IO流把图片保存?
- 想做网络方面的项目,比如基于TCP/IP网络管理,网络安全,IP移动技术,IPv6等,我不知道用什么语言比较适合?
- 如何打印C#中使用的ActiveX控件
- 求教:关于C#委托的一段代码是什么意思?
- WCF,到底有哪些地方用得上
- 这次我说的很清楚 ,看看楼大侠 急 啊
- 使用如何使用WCF 来宿主一个 WebService
- 批量删除datatable里的row的问题,谢谢大家支持
- 人人都说编程思想最重要,那请问什么是编程思想?请不要推荐看什么什么书,能让我看看你的具体例子吗?
- 关于串口通信的几个问题,请大虾们指点下!
- 通常每个套接字地址(协议/网络地址/端口)只允许使用一次。本用的是udpclient进行绑定的。
看看这个文件呢
这句话获取到的是vshost那个文件