其實(shí),不用那么麻煩的自己寫程序去讀取和寫入ini配置文件,直接調(diào)用API就好了。
點(diǎn)擊此處下載全部源程序IniFile.cs
【下載說明】
1、單擊上面這個(gè)地址,打開下載頁(yè)面。
2、點(diǎn)普通下載--等待30秒--點(diǎn)“下載”按鈕--保存
主要源程序:
- using System;
- using System.IO;
- using System.Runtime.InteropServices;
- using System.Text;
-
- //IniFile ini = new IniFile("C:\\test.ini");
- //ini.IniWriteValue("Info","Name",name.Text);
- //ini.IniWriteValue("Info","LastName",lname.Text);
-
- //IniFile ini = new IniFile("C:\\test.ini");
- //name.Text= ini.IniReadValue("Info","Name");
- //lname.Text = ini.IniReadValue("Info","LastName");
-
- namespace PengJun
- {
- /// <summary>
- /// Create a New INI file to store or load data
- /// </summary>
- public class IniFile
- {
- public string path;
-
- [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);
-
- /// <summary>
- /// INIFile Constructor.
- /// </summary>
- /// <param name="INIPath"></param>
- public IniFile(string INIPath)
- {
- path = INIPath;
- }
- /// <summary>
- /// Write Data to the INI File
- /// </summary>
- /// <param name="Section"></param>
- /// Section name
- /// <param name="Key"></param>
- /// Key Name
- /// <param name="Value"></param>
- /// Value Name
- public void IniWriteValue(string Section,string Key,string Value)
- {
- WritePrivateProfileString(Section,Key,Value,this.path);
- }
-
- /// <summary>
- /// Read Data Value From the Ini File
- /// </summary>
- /// <param name="Section"></param>
- /// <param name="Key"></param>
- /// <param name="Path"></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();
-
- }
- }
- }
【更多閱讀】
- [原]WMICodeCreator:C#產(chǎn)生WMI代碼的工具
- [原]Cls_Ini.cls:VB寫的操作ini配置文件的類
- [原]GetIcons:C#提取應(yīng)用程序的圖標(biāo)資源
- [原]Baidu:C#利用百度來搜索網(wǎng)頁(yè)、圖片、視頻等等
- [原]ManageStartUpApps:C#操作注冊(cè)表來讀取和修改開機(jī)啟動(dòng)項(xiàng)
- [原]Baidu:C#利用百度來搜索網(wǎng)頁(yè)、圖片、視頻等等
- [譯]用C#檢測(cè)你的打印機(jī)是否連接
- [原]WMICodeCreator:C#產(chǎn)生WMI代碼的工具
- [原]使用Excel的VBA來讀取和修改bmp位圖像素?cái)?shù)據(jù)
- [原]DownloadWebImages:下載某頁(yè)面上的所有圖片
本站僅提供存儲(chǔ)服務(wù),所有內(nèi)容均由用戶發(fā)布,如發(fā)現(xiàn)有害或侵權(quán)內(nèi)容,請(qǐng)
點(diǎn)擊舉報(bào)。