修改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");

ini,config文件的读取修改的更多相关文章

  1. 如何使用App.config文件,读取字符串?

    如何使用App.config文件,读取字符串? .在项目里添加App.config文件,内容如下: <?xml version="1.0" encoding="ut ...

  2. 一步步开发自己的博客 .NET版(11、Web.config文件的读取和修改)

    Web.config的读取 对于Web.config的读取大家都很属性了.平时我们用得比较多的就是appSettings节点下配置.如: 我们对应的代码是: = ConfigurationManage ...

  3. C# app.config文件配置和修改

    很多时候我们需要对系统的.config文件进度读写操作,例如:系统初始化的参数的更改.系统参数的改变都需要更新到配置文件. 首先我们有必要了解一下app.config.exe.config和vshos ...

  4. ASP.NET 一步步开发自己的博客 .NET版(11、Web.config文件的读取和修改)

    原文:http://www.cnblogs.com/zhaopei/p/5677053.html

  5. [转载]C# 中Web.config文件的读取与写入

    asp.net2.0新添加了对web.config直接操作的功能.开发的时候有可能用到在web.config里设置配置文件,其实是可以通过程序来设置这些配置节的. asp.net2.0需要添加引用: ...

  6. C# 中Web.config文件的读取与写入

    asp.net2.0新添加了对web.config直接操作的功能.开发的时候有可能用到在web.config里设置配置文件,其实是可以通过程序来设置这些配置节的. asp.net2.0需要添加引用: ...

  7. 从Config文件中读取节点的配置信息

    下面是web.config中与本内容有关的细节 <appSettings> <add key="servername" value="www" ...

  8. config 文件读取

    在项目中我们经常要使用到config文件进行相应的配置,来使我们的项目更加灵活健壮. 最常见的就connetionStrings .appSettings这两个节点,那么我们怎么读取呢? 1.首先 我 ...

  9. C#对config.ini文件进行读取和修改

    C#对config.ini文件进行读取和修改: public partial class Patrolcar : Form之后可以加入如下类: #region public class IniFile ...

随机推荐

  1. .Net使用CDO发送邮件,需安装注册的组件

    regsvr32 C:\Program Files\Common Files\System\ado\msado15.dll regsvr32 CDOEX.DLL

  2. BLE GATT 介绍

    做 BLE 快两年了,想想刚开始自己查各种资料学习的时候也是有很多感慨,记得最清楚的就是 GATT 这个东东,当时完全搞不懂,什么是服务?什么是特征值?什么是 UUID?最近感觉对这些概念又有点混乱了 ...

  3. postgressql安装

    参考文章 FreeBSD10.0下ports安装postgresql9.4-server: http://download.csdn.net/detail/machen_smiling/8425613 ...

  4. 在express项目中有效组织和使用mongoose

    平凡之路 1.创建express项目 express mongooseExpress 2.最简express var express = require("express"); v ...

  5. [转]Android 延迟执行

    开启新线程 new Thread(new Runnable(){ public void run(){ Thread.sleep(XXXX); handler.sendMessage(); //告诉主 ...

  6. 利用utl_file来读取文件.

    以前写过用external table来加载trace文件,详情参考下面链接. http://www.cnblogs.com/princessd8251/p/3779145.html 今天要做到是用U ...

  7. saltstack之(十二)配置管理mount

    线上很多服务器都需要挂载存储上的公共目录,并实现开机启动(/etc/fstab),比如web的静态文件共享目录,日志远程集中收集等. 一.批量挂载部分. 1.在node1上配置nfs服务器,有关nfs ...

  8. Linux绑定双网卡

    Linux绑定双网卡 1. 配置参数文件 版本在centos6以下在/etc/modproe.conf文件中配置,版本是centos6.x或以上在/etc/modproe.d/目录下配置. 2.    ...

  9. PHP如何解决网站大流量与高并发的问题

    首先,确认服务器硬件是否足够支持当前的流量. 普通的P4服务器一般最多能支持每天10万独立IP,如果访问量比这个还要大, 那么必须首先配置一台更高性能的专用服务器才能解决问题 ,否则怎么优化都不可能彻 ...

  10. Can't find keyplane that supports type 4 for keyboard iPhone-Portrait-NumberPad; using 3876877096_Portrait_iPhone-Simple-Pad_Default

    在Xcode6下的模拟器点击UITextField控件显示键盘时会显示如下错误提示: Can’t find keyplane that supports type 4 for keyboard iPh ...