asp.net| Example | download
(i). function
Action profile [*.ini] class
(ii). Code
1. Core class file INIFILE.cs code
1///<summary>
2///INIFILE Operation class
3///</summary>
4 public class INIFILE
5 {
6 [DllImport ("kernel32")]
7 private static extern long WritePrivateProfileString (string section,string key,string val,string filePath);
8
9 [DllImport ("kernel32")]
A private static extern int getprivateprofilestring (string section,string key,string def, StringBuilder retval,int si Ze,string FilePath);
11
12//The file path to access
private string strFilePath;
14
public string FilePath
16 {
strFilePath {return;}
set {strFilePath = value;}
19}
20
Public INIFILE ()
22 {
23}
24
INIFILE Public (String strFilePath)
26 {
This.strfilepath = strFilePath;
28}
29
public void WriteValue (string strsection,string strkey,string strvalue)
31 {
if (filepath.length = 0)
33 {
throw new Exception ("No Path set");
35}
WritePrivateProfileString (Strsection, strkey, strvalue, this.) FilePath);
37}
38
ReadValue string (string strsection,string strkey)
40 {
if (filepath.length = 0)
42 {
throw new Exception ("No Path set");
44}
StringBuilder sb = new StringBuilder ();
the int i = getprivateprofilestring (strsection, Strkey, "", SB, 255, this.) FilePath);
Return SB. ToString ();
48}
49}
2. Background Call file INIFile.aspx.cs code
1 protected void Page_Load (object sender, EventArgs e)
2 {
3//read
4 INIFILE ini = new INIFILE ();
5 INI. FilePath = Request.physicalapplicationpath + "Ini.ini";
6 string strreturnvalue = ini. ReadValue ("Annabelle", "Time");
7 Response.Write (Strreturnvalue);
8
9//write
INIFILE ini = new INIFILE ();
One INI. FilePath = Request.physicalapplicationpath + "Ini.ini";
A string strreturnvalue = ini. ReadValue ("Annabelle", "Time");
Response.Write (Strreturnvalue);
INI. WriteValue ("Annabelle", "Time", "0");
Strreturnvalue = ini. ReadValue ("Annabelle", "Time");
Response.Write (Strreturnvalue);
17}
(iii). Sample code Download
Http://www.cnblogs.com/Files/ChengKing/ReadSettingFile.rar