社区
C#
帖子详情
C#中如何读、写INI配置文件?
alf
2003-10-24 11:00:42
如题!
...全文
102
2
打赏
收藏
C#中如何读、写INI配置文件?
如题!
复制链接
扫一扫
分享
转发到动态
举报
AI
作业
写回复
配置赞助广告
用AI写文章
2 条
回复
切换为时间正序
请发表友善的回复…
发表回复
打赏红包
qiuji
2003-10-24
打赏
举报
回复
C#读写INI文件:
http://www.zdnet.com.cn/developer/code/story/0,2000081534,39065664,00.htm
http://developer.ccidnet.com/pub/article/c1137_a26002_p1.html
bGene
2003-10-24
打赏
举报
回复
加载命名空间:
using System.Text;
using System.Runtime.InteropServices;
调用API
[DllImport("kernel32")]
private static extern long WritePrivateProfileString(string section,string key,string val,string filePath);
[DllImport("kernel32")]
private static extern int GetPrivateProfileString(string section,string key,string def,StringBuilder retVal,int size,string filePath);
写INI文件
string FilePath = Application.StartupPath + "Test.ini";
string Section = "Section"; //段落名
string Key = "Key"; //节点名
string KeyValue = "KeyValue"; //节点值
long temp = WritePrivateProfileString(Section,Key,KeyValue,FilePath);
if(temp>0)
MessageBox.Show("成功写入INI文件!","信息");
读INI文件
StringBuilder Temp = new StringBuilder(255);
string FilePath = Application.StartupPath + "Test.ini";
string Section = "Section"; //段落名
string Key = "Key"; //节点名
int i = GetPrivateProfileString ( Section,Key,"无法读取对应数值!",Temp,255,FilePath);
//显示读取的数值
MessageBox.Show(Temp.ToString());
C#
基本
读
取和
写
入
INI
配置文件
C#
基本
读
取和
写
入
INI
配置文件
C#
WinForm
读
写
INI
文件
C#
WinForm
读
写
INI
文件
C#
WinForm
读
写
INI
文件
C#
WinForm
读
写
INI
文件
C#
读
/
写
.
ini
配置文件
的通用操作类,参数可以分组,具体看描述
1、
读
var unitId = Operate
Ini
File.Read
Ini
Data("Unit", "UnitId", "
ini
中
没有值时,赋默认值xxx", "ShareInfo.
ini
路径xx"); 2、
写
Operate
Ini
File.Write
Ini
Data("Unit", "UnitId", "076a0a4d-c417-4fee-902f-245e95179179", "ShareInfo.
ini
路径xx"); 3、
ini
文件结构 [DB] ip=192.168.0.3 name=ZhJingDataBase user=sa password=Sa123 [Unit] UnitBm=1923 UnitId=076a0a4d-c417-4fee-902f-245e95179179 WebSitePath=G:\WebSite
C#
读
取和
写
入
INI
配置文件
读
取和
写
入
INI
配置文件
,熟肉下载即可食用。 private static
Ini
File _file; private static void Test() { string strPath = AppDomain.CurrentDomain.BaseDirectory; //初始化文件 _file = new
Ini
File(strPath + "config.
ini
"); //表示为
读
取CONFIG节点下AAA字段的值(在没有取得数据时默认值为NONE) //同理可以
读
取任意节点下任意字段的值 string readStr = _file.ReadString("CONFIG", "AAA", "NONE"); //表示为
写
入CONFIG节点下BBB字段的值 //同理可以
写
入任意节点下任意字段的值 _file.WriteString("CONFIG", "BBB", "NONE"); //表示为删除CONFIG节点下CCC字段 //同理可以删除任意节点下的任意字段 _file.DeleteKey("CONFIG", "CCC"); }
C#
读
写
INI
配置文件
的类
自己整理的一个
C#
读
写
INI
配置文件
的类,注释清楚,下载即可用
C#
111,098
社区成员
642,554
社区内容
发帖
与我相关
我的任务
C#
.NET技术 C#
复制链接
扫一扫
分享
社区描述
.NET技术 C#
社区管理员
加入社区
获取链接或二维码
近7日
近30日
至今
加载中
查看更多榜单
社区公告
让您成为最强悍的C#开发者
试试用AI创作助手写篇文章吧
+ 用AI写文章