To write to the file:
System.IO.File.WriteAllLines("arquivo.txt", new string[]
{
string.Format("{0}|{1}", textbox1.ID, textbox1.Text),
string.Format("{0}|{1}", textbox2.ID, textbox2.Text),
});
To read:
string[] linhas = System.IO.File.ReadAllLines("arquivo.txt");
foreach (string linha in linhas)
{
string[] separadores = new string[1] { "|" };
string[] tokens = linha.Split(separadores);
if (token.Length == 2)
{
string id = token[0];
string valor = token[1];
Func<string, System.Windows.Forms.Control, System.Windows.Forms.Control> getControle = (id, controle) =>
{
if (!string.IsNullOrEmpty(id))
{
if (controle.ID == id)
{
return controle;
}
if (controle.Controls != null && controle.Controls.Any())
{
foreach (var c in controle.Controls)
{
if (c.ID == id)
{
return c;
}
System.Windows.Forms.Control child;
child = getControle(c, id);
return child;
}
}
}
return null;
}
System.Windows.Forms.TextBox textbox = getControle(id, <seuform>) as System.Windows.Forms.TextBox;
if (textbox != null)
{
textbox.Text = valor;
}
}
}