0

hi everybody
i just wanna ask why is this windows application code read the file once ?
when i click the button it displays the text once..
why isn't be repeated?

 private void button1_Click(object sender, EventArgs e)
    {
        string filename = "c:\\flights.txt";
        FileStream fs = new FileStream(filename, FileMode.Open, FileAccess.Read);
        StreamReader sr = new StreamReader(fs);
        textBox1.Text = sr.ReadToEnd();
        sr.Close();


    }

thanx

Edited by Reverend Jim: Fixed formatting

4
Contributors
3
Replies
4
Views
7 Years
Discussion Span
Last Post by margani
0

textBox1.Text = sr.ReadToEnd(); you say remove the text in the textbox1 then put instead the text in the file if you need to append it use textBox1.Text += sr.ReadToEnd();

0

What your code is actually doing is :

open a textfile
read the whole text
fill a textbox with the text
close a textfile

Do yo see any repetition here? I don't. You fill the textbox with the same text every time you click your button.

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.