You can achieve readings for the INI file by calling two APIs: WritePrivateProfileString, getPrivateProfileString in kernel32.dll.
Code is embodied as follows: using System; using System.Drawing; using System.Collections; using System.ComponentModel; using System.Windows.Forms; using System.Data; using System.Runtime.InteropServices; using System.Text;
namespace iniprocess {public class Form1: System.Windows.Forms.Form {private System.Windows.Forms.TextBox textBox1; private System.Windows.Forms.Button button2; private System.Windows.Forms.Button button1; [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, string filepath) // a function of the ini file write operation {WritePrivateProfileString (Section, Key, Value, filepath);} public string IniReadValue (string Section, string Key, string FilePath) / / Function to the INI file {STRINGBUILDER TEMP = New StringBuilder (255); Int i = getPrivateProfileString (Section, Key, ", TEMP, 255, FilePath; Return Temp.toString ();
}
Private void button1_click (object sender, system.eventargs e) {this.textbox1 .text = inireadvalue ("ODBC 32 Bit Data Sources", "MS Access Database", "E: //Temp//odbc.ini");}
Private void button2_click (object sender, system.eventargs e) {INIWRITEVALUE ("ODBC 32 Bit Data Sources", "MS Access Database", this.TextBox1 .text, "E: //Temp//odbc.ini"); }