asp.net INI文件讀寫類
更新時(shí)間:2009年09月18日 13:24:32 作者:
INI文件讀寫類實(shí)現(xiàn)代碼。
復(fù)制代碼 代碼如下:
using System;
using System.Runtime.InteropServices;
using System.Text;
using System.IO;
namespace Common
{
/// <summary>
/// INI文件讀寫類。
/// </summary>
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);
/// <summary>
/// 寫INI文件
/// </summary>
/// <param name="Section"></param>
/// <param name="Key"></param>
/// <param name="Value"></param>
public void IniWriteValue(string Section,string Key,string Value)
{
WritePrivateProfileString(Section,Key,Value,this.path);
}
/// <summary>
/// 讀取INI文件
/// </summary>
/// <param name="Section"></param>
/// <param name="Key"></param>
/// <returns></returns>
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;
}
/// <summary>
/// 刪除ini文件下所有段落
/// </summary>
public void ClearAllSection()
{
IniWriteValue(null,null,null);
}
/// <summary>
/// 刪除ini文件下personal段落下的所有鍵
/// </summary>
/// <param name="Section"></param>
public void ClearSection(string Section)
{
IniWriteValue(Section,null,null);
}
}
}
沒有太多含量,做雕蟲小技是還是用得上。
相關(guān)文章
asp.net訪問網(wǎng)絡(luò)路徑方法(模擬用戶登錄)
這篇文章主要介紹了asp.net訪問網(wǎng)絡(luò)路徑方法,其實(shí)就是模擬用戶登錄,需要的朋友可以參考下2014-08-08
ASP.NET MVC中為DropDownListFor設(shè)置選中項(xiàng)的方法
這篇文章主要介紹了ASP.NET MVC中為DropDownListFor設(shè)置選中項(xiàng)的方法,需要的朋友可以參考下2014-10-10
Asp.Net MVC4通過id更新表單內(nèi)容的思路詳解
一個(gè)表單一旦創(chuàng)建完,其中大部分的字段便不可再編輯。只能編輯其中部分字段。下面通過本文給大家分享Asp.Net MVC4通過id更新表單內(nèi)容的思路詳解,需要的朋友參考下吧2017-07-07
ASP.NET?Core?MVC中Tag?Helpers用法介紹
這篇文章介紹了ASP.NET?Core?MVC中Tag?Helpers的用法,對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2022-02-02
asp.net 退出登陸(解決退出后點(diǎn)擊瀏覽器后退問題仍然可回到頁面問題)
退出登陸是再常見不過的了,先清除Session,再轉(zhuǎn)到登陸頁面2009-04-04
asp.net使用LINQ to SQL連接數(shù)據(jù)庫及SQL操作語句用法分析
這篇文章主要介紹了asp.net使用LINQ to SQL連接數(shù)據(jù)庫及SQL操作語句用法,較為詳細(xì)的分析了LINQ操作sql語句的功能、使用方法與相關(guān)注意事項(xiàng),需要的朋友可以參考下2016-05-05
使CheckBoxList的Attributes屬性生效(修改微軟的一個(gè)bug)
使CheckBoxList的Attributes屬性生效(修改微軟的一個(gè)bug)...2007-08-08
asp.net下將頁面內(nèi)容導(dǎo)入到word模板中的方法
asp.net下將頁面內(nèi)容導(dǎo)入到word模板中的方法,需要的朋友可以參考下。2010-10-10

