读写配置文件的源码
哪位兄台有读写配置文件的源码,能否拿出来小弟分享下。
------解决方案--------------------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