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?
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Posted May 25, 2011, 9:08 AM
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.
MukundPosted May 26, 2011, 5:42 AM
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