• 博客园logo
  • 会员
  • 周边
  • 新闻
  • 博问
  • 闪存
  • 众包
  • 赞助商
  • Chat2DB
    • 搜索
      所有博客
    • 搜索
      当前博客
  • 写随笔 我的博客 短消息 简洁模式
    用户头像
    我的博客 我的园子 账号设置 会员中心 简洁模式 ... 退出登录
    注册 登录
HS.H °
财富来源于拼搏, 命运取决与奋斗!
博客园    首页    新随笔    联系   管理    订阅  订阅

ini,config文件的读取修改

修改ini配置文件

// 声明INI文件的写操作函数 WritePrivateProfileString()

[System.Runtime.InteropServices.DllImport("kernel32")]

private static extern long WritePrivateProfileString(string section, string key, string val, string filePath);

// 声明INI文件的读操作函数 GetPrivateProfileString()

[System.Runtime.InteropServices.DllImport("kernel32")]

private static extern int GetPrivateProfileString(string section, string key, string def, System.Text.StringBuilder retVal, int size, string filePath);

 

StringBuilder temp = new StringBuilder(255);
string FileName = FrmSelectPath.selectPath + "\\dbconfig.ini";//ini文件路径
int i = GetPrivateProfileString("dbinfo", "database", "", temp, 255, FileName);
if (i != 0)
{
string keyValue = dbname;//键值
WritePrivateProfileString("dbinfo", "database", server, FileName);
WritePrivateProfileString("dbinfo", "user", username, FileName);
WritePrivateProfileString("dbinfo", "pwd", userpwd, FileName);
WritePrivateProfileString("Remort", "baseInfoUrl", @"tcp://"+Remoting+@"/BaseInfo", FileName);
WritePrivateProfileString("Remort", "commonUrl", @"tcp://"+Remoting+@"/Common", FileName);
WritePrivateProfileString("Remort", "Interface", @"tcp://"+Remoting+@"/", FileName);
}
else
{
MessageBox.Show("修改后台配置文件出错!");
}

 

 

修改config配置文件

//需要引用命名空间 using System.Xml;
xmldocument xdc = new xmldocument();
xdc.Load(FrmSelectPath.selectPath + "\\FrontInterface.exe.config");
string sqlConnection = "Provider=SQLOLEDB;Data Source="+server+";Initial Catalog="+dbname+";Integrated Security=SSPI;";
foreach(XmlNode xnode in xdc["configuration"]["appSettings"].ChildNodes)
{
string keyStr = xnode.Attributes["key"].Value;
XmlElement xel =(XmlElement)xnode;
if(keyStr=="connString")
{
xel.SetAttribute("value",sqlConnection);
}
if(keyStr == "Interface1" || keyStr == "Interface" || keyStr == "InterfaceRun" )
{
xel.SetAttribute("value",@"tcp://"+Remoting+@"/");
}
}
xdc.Save(FrmSelectPath.selectPath+"\\FrontInterface.exe.config");


作者:wangqc
出处:http://www.cnblogs.com/wangqc/
本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接,否则保留追究法律责任的权利。
该文章也同时发布在我的独立博客中-wangqc。

posted @ 2013-08-10 10:12  没有终点的列车  阅读(1231)  评论(0)    收藏  举报
刷新页面返回顶部
博客园  ©  2004-2025
浙公网安备 33010602011771号 浙ICP备2021040463号-3