·您的位置: 首页 » 资源教程 » 编程开发 » ASP.NET » 常用的读写ini文件的类

常用的读写ini文件的类

类别: ASP.NET教程  评论数:0 总得分:0
using System;
using System.IO;
using System.Runtime.InteropServices;
using System.Text;
using Microsoft.Win32;

namespace Wjb.ReadOrWriteIniAndReg
{
/// <summary>
/// RWIni 的摘要说明。
/// 读写ini文件类
/// 类库开发:吴剑冰
/// 时间:2003年10月20日
/// 功能:读写INI文件
/// </summary>
public class RWIni
{
private static string FileName;

[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
);

/// <summary>
///构造读写全路径为filename的ini文件的类
/// </summary>
/// <param name="filename"></param>
public RWIni(string filename)
{
//
// 构造函数
//
FileName=filename;
}
/// <summary>
/// 读取整型数据
/// </summary>
/// <param name="section"></param>
/// <param name="key"></param>
/// <param name="def"></param>
/// <returns></returns>
public int GetInt(string section,string key,int def)
{
return GetPrivateProfileInt(section,key,def,FileName);
}
/// <summary>
/// 读取字符串数据
/// </summary>
/// <param name="section"></param>
/// <param name="key"></param>
/// <param name="def"></param>
/// <returns></returns>
public string GetString(string section,string key,string def)
{
StringBuilder temp=new StringBuilder(1024);
GetPrivateProfileString(section,key,def,temp,1024,FileName);
return temp.ToString();
}
/// <summary>
/// 写入整型数据
/// </summary>
/// <param name="section"></param>
/// <param name="key"></param>
/// <param name="iVal"></param>
public void WriteInt(string section,string key,int iVal)
{
WritePrivateProfileString(section,key,iVal.ToString(),FileName);
}
/// <summary>
/// 写入字符串数据
/// </summary>
/// <param name="section"></param>
/// <param name="key"></param>
/// <param name="strVal"></param>
public void WriteString(string section,string key,string strVal)
{
WritePrivateProfileString(section,key,strVal,FileName);
}
/// <summary>
/// 删除键值
/// </summary>
/// <param name="section"></param>
/// <param name="key"></param>
public void DelKey(string section,string key)
{
WritePrivateProfileString(section,key,null,FileName);
}
/// <summary>
/// 删除模块
/// </summary>
/// <param name="section"></param>
public void DelSection(string section)
{
WritePrivateProfileString(section,null,null,FileName);
}
}
}





-= 资 源 教 程 =-
文 章 搜 索
关键词:
类型:
范围:
纯粹空间 softpure.com
Copyright © 2006-2008 暖阳制作 版权所有
QQ: 15242663 (拒绝闲聊)  Email: faisun@sina.com
 纯粹空间 - 韩国酷站|酷站欣赏|教程大全|资源下载|免费博客|美女壁纸|设计素材|技术论坛   Valid XHTML 1.0 Transitional
百度搜索 谷歌搜索 Alexa搜索 | 粤ICP备19116064号-1