Copy codeThe Code is as follows:
Using System;
Using System. Data;
Using System. Configuration;
Using System. Web;
Using System. Web. Security;
Using System. Web. UI;
Using System. Web. UI. WebControls;
Using System. Web. UI. WebControls. WebParts;
Using System. Web. UI. HtmlControls;
Using System. Runtime. InteropServices;
Using System. Text;
Namespace CreateWebDir
{
/// <Summary>
/// Summary of INIFile
/// </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 );
Public void IniWriteValue (string Section, string Key, string Value)
{
WritePrivateProfileString (Section, Key, Value, this. path );
}
Public string IniReadValue (string Section, string Key)
{
StringBuilder temp = new StringBuilder (255 );
Int I = GetPrivateProfileString (Section, Key, "", temp, 255, this. path );
Return temp. ToString ();
}
}
}
Copy codeThe Code is as follows:
Using System;
Using System. Data;
Using System. Configuration;
Using System. Collections;
Using System. Web;
Using System. Web. Security;
Using System. Web. UI;
Using System. Web. UI. WebControls;
Using System. Web. UI. WebControls. WebParts;
Using System. Web. UI. HtmlControls;
Using System. IO;
Public partial class user_Default: System. Web. UI. Page
{
Protected void Page_Load (object sender, EventArgs e)
{
CreateWebDir. INIFile AB = new CreateWebDir. INIFile (@ "F: \ test ");
String iniFile = @ "F: \ test. ini ";
If (! File. Exists (iniFile ))
{
Using (FileStream fs = File. Create (iniFile ))
{
Fs. Close ();
}
}
String [] args = new string [10];
CreateWebDir. INIFile myINI = new CreateWebDir. INIFile (iniFile );
For (int I = 0; I <args. Length; I ++)
{
Args [I] = Convert. ToString (I + I * I );
MyINI. IniWriteValue ("WebDir", "arg" + I. ToString (), args [I]);
}
}
}
Copy codeThe Code is as follows:
Using System;
Using System. Data;
Using System. Configuration;
Using System. Collections;
Using System. Web;
Using System. Web. Security;
Using System. Web. UI;
Using System. Web. UI. WebControls;
Using System. Web. UI. WebControls. WebParts;
Using System. Web. UI. HtmlControls;
Using System. IO;
Public partial class user_Default: System. Web. UI. Page
{
Protected void Page_Load (object sender, EventArgs e)
{
CreateWebDir. INIFile AB = new CreateWebDir. INIFile (@ "F: \ test. ini ");
Response. Write (AB. IniReadValue ("WebDir", "arg5 "));
}
}