C# 操作INI文件
来源:百度文库 编辑:神马文学网 时间:2024/04/29 22:31:58
//写INI文件
[ DllImport ( "kernel32" ) ]
private static extern bool WritePrivateProfileString ( string section ,string key , string val , string filePath ) ;
//读ini文件(字符
[ DllImport ( "kernel32" ) ]
private static extern int GetPrivateProfileString ( string section,string key , string def , StringBuilder retVal ,int size , stringfilePath ) ;
//读ini文件(数字
[ DllImport ( "kernel32" ) ]
private static extern int GetPrivateProfileInt ( string section ,string key , int def , string filePath ) ;
//////////////////////////////////////////////////////////////
using System;
using System.IO;
using System.Runtime.InteropServices;
using System.Text;
namespace EchonComponentLibrary
{
///
/// IniFile 的摘要说明。
///
public class IniFile
{
private string FFileName;
[DllImport("kernel32")]
private static extern int GetPrivateProfileInt(
string lpAppName,
string lpKeyName,
int nDefault,
string lpFileName
);
[DllImport("kernel32")]
private static extern int GetPrivateProfileString(
string lpAppName,
string lpKeyName,
string lpDefault,
StringBuilder lpReturnedString,
int nSize,
string lpFileName
);
[DllImport("kernel32")]
private static extern bool WritePrivateProfileString(
string lpAppName,
string lpKeyName,
string lpString,
string lpFileName
);
public IniFile(string filename)
{
FFileName = filename;
}
public int ReadInt(string section,string key,int def)
{
return GetPrivateProfileInt(section,key,def,FFileName);
}
public string ReadString(string section,string key,string def)
{
StringBuilder temp = new StringBuilder(1024);
GetPrivateProfileString(section,key,def,temp,1024,FFileName);
return temp.ToString();
}
public void WriteInt(string section,string key,int iVal)
{
WritePrivateProfileString(section,key,iVal.ToString(),FFileName);
}
public void WriteString(string section,string key,string strVal)
{
WritePrivateProfileString(section,key,strVal,FFileName);
}
public void DelKey(string section,string key)
{
WritePrivateProfileString(section,key,null,FFileName);
}
public void DelSection(string section)
{
WritePrivateProfileString(section,null,null,FFileName);
}
}
}
[ DllImport ( "kernel32" ) ]
private static extern bool WritePrivateProfileString ( string section ,string key , string val , string filePath ) ;
//读ini文件(字符
[ DllImport ( "kernel32" ) ]
private static extern int GetPrivateProfileString ( string section,string key , string def , StringBuilder retVal ,int size , stringfilePath ) ;
//读ini文件(数字
[ DllImport ( "kernel32" ) ]
private static extern int GetPrivateProfileInt ( string section ,string key , int def , string filePath ) ;
//////////////////////////////////////////////////////////////
using System;
using System.IO;
using System.Runtime.InteropServices;
using System.Text;
namespace EchonComponentLibrary
{
///
/// IniFile 的摘要说明。
///
public class IniFile
{
private string FFileName;
[DllImport("kernel32")]
private static extern int GetPrivateProfileInt(
string lpAppName,
string lpKeyName,
int nDefault,
string lpFileName
);
[DllImport("kernel32")]
private static extern int GetPrivateProfileString(
string lpAppName,
string lpKeyName,
string lpDefault,
StringBuilder lpReturnedString,
int nSize,
string lpFileName
);
[DllImport("kernel32")]
private static extern bool WritePrivateProfileString(
string lpAppName,
string lpKeyName,
string lpString,
string lpFileName
);
public IniFile(string filename)
{
FFileName = filename;
}
public int ReadInt(string section,string key,int def)
{
return GetPrivateProfileInt(section,key,def,FFileName);
}
public string ReadString(string section,string key,string def)
{
StringBuilder temp = new StringBuilder(1024);
GetPrivateProfileString(section,key,def,temp,1024,FFileName);
return temp.ToString();
}
public void WriteInt(string section,string key,int iVal)
{
WritePrivateProfileString(section,key,iVal.ToString(),FFileName);
}
public void WriteString(string section,string key,string strVal)
{
WritePrivateProfileString(section,key,strVal,FFileName);
}
public void DelKey(string section,string key)
{
WritePrivateProfileString(section,key,null,FFileName);
}
public void DelSection(string section)
{
WritePrivateProfileString(section,null,null,FFileName);
}
}
}
C# 操作INI文件
C# 操作INI文件
ini文件操作类模块
C#文件操作
INI文件编程
ini 文件操作记要(1): 使用 TIniFile - 万一的 Delphi 博客 - 博客园
C# 文件操作(上传 下载 删除 文件列表...) - 《八零年代》.NET之家 - 博客...
INI文件格式及其操作代码
硬件设置文件win.ini文件详解
怎样在C#里对xml文件进行修改,新增,删除,插入操作?
ini文件的创建读写(含源码)
在VC 中读写INI文件
VB.NET访问INI文件代码实现
在VB应用程序中使用INI文件
VC进程通信之:操作配置文件ini
C#操作XML简要教程
C#操作XML简要教程
删除desktop_.ini文件,彻底摧毁熊猫烧香(worm.nimaya)
在VC 中读写INI文件 - 技术收藏 - CSDN博客
删除desktop_.ini文件,彻底摧毁熊猫烧香(worm.nimaya)
有关“确定要移除只读文件‘Desktop_.ini’吗?”
用c#制作pdf文件全攻略
C# 读写Config文件(App.config)
C# 读写Config文件(App.config