Originariamente inviato da anatasio
Questo è il codice di quando apre il primo Form:
string PathDelFileIni;
PathDelFileIni = "\\\\PORTATILEHP6715\\esprit\\Esprit.ini";
MessageBox.Show(PathDelFileIni);
ini = new IniIO(PathDelFileIni);
string sezione = "Connect";
try
{
T_Utente.Text = ini.Read(sezione, "UID");
T_Password.Text = ini.Read(sezione, "PWD");
T_Database.Text = ini.Read(sezione, "DATABASE");
ParametriDatabase.server = ini.Read(sezione, "SERVER");
ParametriDatabase.dsn = ini.Read(sezione, "DSN");
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
E questa è la classe IniIO che utilizza:
class IniIO
{
private string Path;
[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 string Read(string Section, string Key)
{
StringBuilder temp = new StringBuilder(255);
int i = GetPrivateProfileString(Section, Key, "", temp, 255, this.Path);
return temp.ToString();
}
}