- 相關(guān)推薦
asp.net 操作INI文件讀寫(xiě)類(lèi)實(shí)例代碼
復(fù)制代碼 代碼如下:
using System;
using System.Runtime.InteropServices;
using System.Text;
using System.IO;
namespace Common
{
///
/// INI文件讀寫(xiě)類(lèi)。
///
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);
///
/// 寫(xiě)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);
}
}
}
沒(méi)有太多含量,做雕蟲(chóng)小技是還是用得上。
【 asp.net 操作INI文件讀寫(xiě)類(lèi)實(shí)例代碼】相關(guān)文章:
用ISO鏡像文件安裝了Xp操作系統(tǒng)的方法教程07-22
數(shù)控編程代碼大全02-13
Java代碼的基本知識(shí)09-03
小升初數(shù)學(xué)的讀寫(xiě)法總結(jié)09-04
網(wǎng)頁(yè)滾動(dòng)文字的制作HTML代碼04-10
勒索病毒文件恢復(fù)201707-16
法律文件長(zhǎng)句翻譯技巧08-30