To write in the archive:
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;
}
}
}
How can I save these strings to a txt: string id1 = "id|192919"; string id2 = "id2|29b9a92"; and then pick up with these strings: string value1 = id1.Substring(id1.Indexof("|") + 1); string value2 = id2.Substring(id2.Indexof("|") + 1);
– user92401
At a glance in this tutorial from MS to save the file
– Barbetta
OK got it, but as I take these id1 and id2 values inside the txt and do the split, that’s what I want, thanks.
– user92401
Do you have any buttons in the form? if yes, inside the click it do
string id1 = textbox1.Text;
at a glance in that video– Barbetta