當前位置:才華齋>設計>網頁設計>

asp.net 操作INI檔案讀寫類例項程式碼

網頁設計 閱讀(3.27W)

操作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);

}

}

}

沒有太多含量,做雕蟲小技是還是用得上。