首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > .NET > C# >

读写配置文件的源码,该怎么处理

2012-02-17 
读写配置文件的源码哪位兄台有读写配置文件的源码,能否拿出来小弟分享下。[解决办法]ini文件吧?可以用其它

读写配置文件的源码
哪位兄台有读写配置文件的源码,能否拿出来小弟分享下。

[解决办法]
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

热点排行