Skip to content

Stream writer

Shyja Abraham

Asked May 25, 2011, 5:00 AM EDTSolved
Share
LinkedInX
  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.

  • ✓ Accepted answer0
    To write the value into txtfile.

    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.
    0
  • 0
    Using System.IO;
    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
    0