This article mainly introduces the asp.net Method for reading and writing ini configuration files. For more information, see
The 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 () ;}} code: using System; using System. data; using System. configuration; using System. collections; using System. web; using Sy Stem. 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]) ;}} the 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 "));}}