C# 读写ini文件
1.添加引用
using System.IO;
using System.Runtime.InteropServices;
2.声明API函数
#region API函数声明
[DllImport("kernel32")]
private static extern long WritePrivateProfileString(string section, string key, string val, string filepath);
[DllImport("kernel32")]
private static extern long GetPrivateProfileString(string section, string key, string def, StringBuilder retval, int size, string filepath);
#endregion
3.文件读取的方法
private string ContentValue(string Section, string key, string strFilePath)
{
StringBuilder temp = new StringBuilder();
GetPrivateProfileString(Section, key, "", temp, , strFilePath);
return temp.ToString();
}
4.读取文件实例
private void button1_Click(object sender, EventArgs e)
{
string path = Application.StartupPath + @"\配置文件.ini";
textBox1.Text = ContentValue("Server", "path", path);
textBox2.Text = ContentValue("Server", "cmd", path);
textBox3.Text = ContentValue("Client", "path", path);
textBox4.Text = ContentValue("Client", "cmd", path);
}
效果图:

C# 读写ini文件的更多相关文章
- c# 利用动态库DllImport("kernel32")读写ini文件(提供Dmo下载)
c# 利用动态库DllImport("kernel32")读写ini文件 自从读了设计模式,真的会改变一个程序员的习惯.我觉得嘛,经验也可以从一个人的习惯看得出来,看他的代码编写习 ...
- VB读写INI文件的四个函数以及相关API详细说明
WritePrivateProfileString函数说明 来源:http://blog.csdn.net/wjb9921/article/details/2005000 在我们写的程序当中,总有一 ...
- C# 读写INI 文件
INI 格式: [Section1] KeyWord1 = Value1 KeyWord2 = Value2 ... [Section2] KeyWord3 = Value3 KeyWord4 = V ...
- WIN32读写INI文件方法
在程序中经常要用到设置或者其他少量数据的存盘,以便程序在下一次执行的时候可以使用,比如说保存本次程序执行时窗口的位置.大小.一些用户设置的 数据等等,在 Dos 下编程的时候,我们一般自己产生一个 ...
- 读写ini文件
C# 使用文件流来读写ini文件 背景 之前采用ini文件作为程序的配置文件,觉得这种结构简单明了,配置起来也挺方便.然后操作方式是通过WindowsAPI,然后再网上找到一个基于WindowsAPI ...
- 在 WinCe 平台读写 ini 文件
在上篇文章开发 windows mobile 上的今日插件时,我发现 wince 平台上不支持例如 GetPrivateProfileString 等相关 API 函数.在网络上我并没有找到令我满意的 ...
- Windows中读写ini文件
.ini 文件是Initialization File的缩写,即初始化文件,是windows的系统配置文件所采用的存储格式,来配置应用软件以实现不同用户的要求.配置文件有很多种如ini配置文件,XML ...
- C#中读写INI文件
C#中读写INI文件 c#的类没有直接提供对ini文件的操作支持,可以自己包装win api的WritePrivateProfileString和GetPrivateProfileString函数实现 ...
- Qt读写ini文件
一 背景 1 ini文件介绍 .ini 文件是Initialization File的缩写,即初始化文件. 除了windows现在很多其他操作系统下面的应用软件也有.ini文件,用来配置应用软件以实现 ...
- 【python-ini】python读写ini文件
[python-ini]python读写ini文件 本文实例讲述了Python读写ini文件的方法.分享给大家供大家参考.具体如下: 比如有一个文件update.ini,里面有这些内容: 1 2 ...
随机推荐
- python版本升级及pip部署方法
Python版本升级 CentOS 6.3自带的Python版本为2.6,首先需要升级到2.7版本.由于旧版本的Python已被深度依赖,所以不能卸载原有的Python,只能全新安装. 1.下载Pyt ...
- Mono资源
摘要 最近看了一部分mono方面的资料,这里整理一下,在这里列一个目录,方便以后用到的时候查找. Mono Mono 是一个由 Xamarin 公司(先前是 Novell,最早为 Ximian)所主持 ...
- XPath使用小结
参考资料: http://www.w3school.com.cn/xpath/xpath_nodes.asp
- jq 构造函数,然后再表单提交过程中对数据进行修改
先贴代码 <script type="text/javascript"> function appendText(){ var content = $("#t ...
- 网页JQ基础之jq-隐藏以及显示特效
简单的 隐藏以及显示的 JQ 的代码如下: <!DOCTYPE html> <html> <head> <script src="/jquery/j ...
- vim如何在多个文件中切换
如果我们一次打开多个文件 看一下当前目录里面的文件: wangkongming@Vostro /data/webroot/testRoot/application/modules/Admin/view ...
- fatal: Paths with -a does not make sense.
git commit -am '*屏蔽设置缓存' htdocs/s.php fatal: Paths with -a does not make sense. 应该用下面的这样. git commit ...
- 在XP、Win7/8上如何右键进入命令行
在Win7/8上特别简单,只需要在按下shift键后,再点击鼠标右键,即可进入命令行界面.
- CF459B Pashmak and Flowers (水
Pashmak and Flowers Codeforces Round #261 (Div. 2) B. Pashmak and Flowers time limit per test 1 seco ...
- git SSH keys
An SSH key allows you to establish a secure connection between your computer and GitLab. Before gene ...