读写配置文件的源码 哪位兄台有读写配置文件的源码,能否拿出来小弟分享下。 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 ini文件吧?可以用其它语言写成DLL,然后再导入,就可以了,也很方便..偶也是一新手,所以用了这种方式.. app.config:<?xml version="1.0" encoding="utf-8" ?><configuration> <appSettings> <add key="ConnectionString" value="Data Source=KYLEYUAN;Initial Catalog=WiseChamp;User ID=sa"/> </appSettings></configuration>=====================读取:using System.Configuration;private static string connectoinString = ConfigurationManager.AppSettings["ConnectionString"];另外还要在Project中加入System.Configuration的引用 写的: XmlDocument xDoc = new XmlDocument(); string filename=Application.ExecutablePath + ".config"; xDoc.Load(filename); XmlNode xNode; XmlElement xElem1; XmlElement xElem2; xNode = xDoc.SelectSingleNode("//appSettings"); xElem1 = (XmlElement)xNode.SelectSingleNode("//add[@key='" + AppKey + "']"); if ( xElem1 != null ) { xElem1.SetAttribute("value",AppValue); } else { xElem2 = xDoc.CreateElement("add"); xElem2.SetAttribute("key",AppKey); xElem2.SetAttribute("value",AppValue); xNode.AppendChild(xElem2); } xDoc.Save(Application.ExecutablePath + ".config"); http://blog.csdn.net/LeoMaya/archive/2007/06/21/1660760.aspx Linq 更新失败 vs2008工具箱里为何没有SaveFileDialog控件? list集合 二个xml转化成一个xml文件! 如何在C#中打印窗体? 关于运行.exe文件问题 最新的.net框架是多少版本?1.1?????哪里有最新的?测试版也行 ads里,修改用户组名称的时候的一个问题,请大家帮忙! 请问怎样才能知道光驱的状态及硬盘的状态????? 如何获得一个目录下的所有文件的文件名?拜托了,c#写的 急!!2003服务器CPU100 %的问题 关闭SqlConnection对象出错
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<appSettings>
<add key="ConnectionString" value="Data Source=KYLEYUAN;Initial Catalog=WiseChamp;User ID=sa"/>
</appSettings>
</configuration>
=====================
读取:
using System.Configuration;private static string connectoinString = ConfigurationManager.AppSettings["ConnectionString"];另外还要在Project中加入System.Configuration的引用
XmlDocument xDoc = new XmlDocument();
string filename=Application.ExecutablePath + ".config";
xDoc.Load(filename);
XmlNode xNode;
XmlElement xElem1;
XmlElement xElem2;
xNode = xDoc.SelectSingleNode("//appSettings");
xElem1 = (XmlElement)xNode.SelectSingleNode("//add[@key='" + AppKey + "']");
if ( xElem1 != null )
{
xElem1.SetAttribute("value",AppValue);
}
else
{
xElem2 = xDoc.CreateElement("add");
xElem2.SetAttribute("key",AppKey);
xElem2.SetAttribute("value",AppValue);
xNode.AppendChild(xElem2);
}
xDoc.Save(Application.ExecutablePath + ".config");