When Winfrom is developed, some system settings are sometimes saved to INI-type files. The following provides the code to manipulate the INI file:
Public Static classinifiles {[DllImport ("kernel32")] Private Static extern LongWritePrivateProfileString (stringSectionstringKeystringValstringFilePath); [DllImport ("kernel32")] Private Static extern intGetPrivateProfileString (stringSectionstringKeystringDef, StringBuilder RetVal,intSizestringFilePath); Public Static stringFilePath; /// <summary> ///Write INI file/// </summary> /// <param name= "section" >project name (e.g. [TypeName])</param> /// <param name= "key" >Key</param> /// <param name= "value" >value</param> Public Static voidIniwritevalue (stringSectionstringKeystringvalue) {writeprivateprofilestring (section, key, value, FilePath); } /// <summary> ///read out INI file/// </summary> /// <param name= "section" >project name (e.g. [TypeName])</param> /// <param name= "key" >Key</param> Public Static stringInireadvalue (stringSectionstringkey) {StringBuilder temp=NewStringBuilder ( -); inti = getprivateprofilestring (section, Key,"", temp, -, FilePath); returntemp. ToString (); } /// <summary> ///Verify that the file exists/// </summary> /// <returns>Boolean value</returns> Public Static BOOLExistinifile () {returnfile.exists (FilePath); } }View Code
C #/S structure Operation INI System file