Click here to Skip to main content
14,735,301 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hello, I'm Trying To SAVE everything typed in the TextBox AS txt file ..
But the problem is that "it saves a blank txt file" !! ,
All the text that typed in the TextBox doesn't appear in the saved txt file .. !! :S
What is wrong here..

private void button1_Click(object sender, EventArgs e)
           Stream myStream;
           SaveFileDialog saveFileDialog1 = new SaveFileDialog();

           saveFileDialog1.Filter = "txt files (*.txt)|*.txt|All files (*.*)|*.*";
           saveFileDialog1.FilterIndex = 1;
           saveFileDialog1.RestoreDirectory = true;

           if (saveFileDialog1.ShowDialog() == DialogResult.OK)
               if ((myStream = saveFileDialog1.OpenFile()) != null)
                   StreamWriter wText = new StreamWriter(myStream);

                   wText.Write(" your text");

Updated 4-Sep-10 3:49am

I realised you have used the code off the following article/post[^].

Note the last item towards the of middle the page - "Just remember to Flush and close your WText object.... otherwise nothing gets written".
Katkot 4-Sep-10 10:04am
Oh yes, I did not notice.
You can also use AutoFlush = true to ensure that the object writes it properly. :rose:

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900