Operation of INI files (ASP.NET + C #)

zhaozj2021-02-17  58

(1) inIfile.cs

Using system; using system.Text;

Namespace CreateweBDir {? ///

? /// inIfile summary description. ? ///

Public Class InIfile

? {

?? public string path;

?? public inIfile (string inipath) ?? {??? path = inipath; ??}

?? [DLLIMPORT ("kernel32")] ?? private static extern long writPrivateProfileString (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);

??? I = getPrivateProfileString (Section, Key, ", TEMP, 255, this.path;

??? Return Temp.toString ();

??}

?}}

============================================================================================================================================================================================================= =====

(2) Example of use

?? String Inifile = @ "d: /bug2000.ini"; ??? if (! file.exists (inifi)) ??? {???? using (filestream fs = file.create (inIfile) ?? ?? {????? fs.close (); ????} ???}

??? INIFILE Myini = new inIfile (InIfile);

??? for (i = 0; i

??? {

???? Myini.iniWriteValue ("WebDir", "arg" i.tostring (), args [i]);

???}

转载请注明原文地址:https://www.9cbs.com/read-28941.html

New Post(0)