- 相关推荐
asp.net 操作INI文件读写类实例代码
复制代码 代码如下:
using System;
using System.Runtime.InteropServices;
using System.Text;
using System.IO;
namespace Common
{
///
/// INI文件读写类。
///
public class INIFile
{
public string path;
public INIFile(string INIPath)
{
path = INIPath;
}
[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);
[DllImport("kernel32")]
private static extern int GetPrivateProfileString(string section, string key, string defVal, Byte[] retVal, int size, string filePath);
///
/// 写INI文件
///
///
///
///
public void IniWriteValue(string Section,string Key,string Value)
{
WritePrivateProfileString(Section,Key,Value,this.path);
}
///
/// 读取INI文件
///
///
///
///
public string IniReadValue(string Section,string Key)
{
StringBuilder temp = new StringBuilder(255);
int i = GetPrivateProfileString(Section,Key,"",temp, 255, this.path);
return temp.ToString();
}
public byte[] IniReadValues(string section, string key)
{
byte[] temp = new byte[255];
int i = GetPrivateProfileString(section, key, "", temp, 255, this.path);
return temp;
}
///
/// 删除ini文件下所有段落
///
public void ClearAllSection()
{
IniWriteValue(null,null,null);
}
///
/// 删除ini文件下personal段落下的所有键
///
///
public void ClearSection(string Section)
{
IniWriteValue(Section,null,null);
}
}
}
没有太多含量,做雕虫小技是还是用得上。
【 asp.net 操作INI文件读写类实例代码】相关文章:
php解析ini配置文件07-13
ASP.NET MVC异常处理模块简单教程-ASP.NET教程实例推荐07-19
ASP.NET连SQL7接口的源代码06-06
Java文件解压缩实例详解201607-26
Linux文件系统操作命令大全07-03
关于ASP.NET使用JavaScript显示信息提示窗口实现原理及代码05-09
Linux操作系统文件系统基础知识07-25
2016职称英语综合类A代码12考试答案09-14
Mac电脑设置自动排列文件图标的操作方法07-04