网站首页 语言 会计 电脑 医学 资格证 职场 文艺体育 范文

asp.net 操作INI文件读写类实例代码

栏目: 网页设计 / 发布于: / 人气:3.34W

操作INI文件读写类实例代码

asp.net 操作INI文件读写类实例代码

复制代码 代码如下:

using System;

using ropServices;

using ;

using ;

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

}

///

/// 读取INI文件

///

///

///

///

public string IniReadValue(string Section,string Key)

{

StringBuilder temp = new StringBuilder(255);

int i = GetPrivateProfileString(Section,Key,"",temp, 255, );

return ring();

}

public byte[] IniReadValues(string section, string key)

{

byte[] temp = new byte[255];

int i = GetPrivateProfileString(section, key, "", temp, 255, );

return temp;

}

///

/// 删除ini文件下所有段落

///

public void ClearAllSection()

{

IniWriteValue(null,null,null);

}

///

/// 删除ini文件下personal段落下的所有键

///

///

public void ClearSection(string Section)

{

IniWriteValue(Section,null,null);

}

}

}

没有太多含量,做雕虫小技是还是用得上。