Copy Code code 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 description 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 Code code 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\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 * i);
Myini.iniwritevalue ("WebDir", "Arg" + i.tostring (), args[i]);
}
}
}
Copy Code code 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\test.ini");
Response.Write (AB. Inireadvalue ("WebDir", "Arg5"));
}
}