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

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();

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.

use textBox1.Text += sr.ReadToEnd();

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.