修改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. 【转】C# 解析 json

    C# 解析 json JSON(全称为JavaScript Object Notation) 是一种轻量级的数据交换格式.它是基于JavaScript语法标准的一个子集. JSON采用完全独立于语言的 ...

  2. hibernate多SessionFactory配置

    <bean id="aDataSource" class="org.apache.commons.dbcp.BasicDataSource" destro ...

  3. 流媒体学习二-------SIP协议学习(基本场景分析 )

    作者:gnuhpc 出处:http://www.cnblogs.com/gnuhpc/ 1.SIP业务基本知识 1.1 业务介绍 会话初始协议(Session Initiation Protocol) ...

  4. uzqp文件的加解密

    帮朋友做的,根据python版本翻译成的java版本,记录一下代码 import java.io.File; import java.io.FileInputStream; import java.i ...

  5. Linux上使用SMART检测硬盘

    SMART(Self-Monitoring, Analysis, and Reporting Technology)是一种普及度比较高的磁盘分析检测工具,磁盘运行过程中,该工具搜集磁盘的状态参数,如型 ...

  6. SqlServer2008R2执行Sql语句,快捷键

    SqlServer2008R2执行Sql语句,快捷键Alt+X

  7. iOS: 实现苹果的内购

    一.介绍: 在个人开发的app上架到AppStore后,苹果官方允许我们将自己的app在appstore上进行付费使用,也就是所谓的内购.其中,支付方式规定的必须是苹果的支付方式:应用内支付. 二.流 ...

  8. JavaScript:通过id来进行元素的取得

    每一个HTML元素都使用id来进行一个标注,随后可以通过document.getElementById(“ID名称”)取得指定的ID元素对象,取得元素对象之后就可以对其进行操作. 但是document ...

  9. 微信公众平台开发(99) 自定义菜单获取OpenID

    关键字 微信公众平台 自定义菜单 OpenID作者:方倍工作室原文:http://www.cnblogs.com/txw1958/p/weixin-menu-get-openid.html 在这篇微信 ...

  10. PISA

    http://www.oecd.org/pisa/ 国际学生评估 PISA类测试:一种国际性的科学的评价方法,可强化对考生知识面.综合分析.创新素养方面的考查. 评估内容 第一次PISA评估于2000 ...