Stream writer
i have a form with 4 textboxes ,1 datetimepicker,1datagridview . how we save the text(myvalue.txt) values of these controls using stream writer and also read from(myvalue.txt) using stream reader. plz help?
2 Answers
Know the answer? Post it. Somebody with the same question will find it here.
Former memberPosted May 25, 2011, 5:08 AM EDT
using (StreamWriter writer = new StreamWriter(""myvalue.txt))
{
writer.WriteLine(
writer.WriteLine("Textbox2 : " + textBox2.Text);
//You can add other control here.
For the gridview you want to write all the records , iterate them gridviewrows...
}
To read the value
using(StreamReader reader= new StreamReader("myvalue.txt")
{
string s = reader.ReadToEnd();
//later you can parse the s variable.
}
Hope this helps you.
Mukund7 pointsPosted May 26, 2011, 1:42 AM EDT
Using SystemsText;
private void CreatetxtFile()
{
StringBuilder sb = new StringBuilder();
sb.AppendLine("test");
sb.AppendLine("= = = = = =");
sb.AppendLine();
sb.Append("test2");
sb.AppendLine();
sb.AppendLine();
using (StreamWriter outfile = new StreamWriter("c:" + @"\AllTxtFiles.txt"))
{
outfile.Write(sb.ToString());
}
}
Thanks
Mukund