Click here to Skip to main content
15,880,608 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");

                   myStream.Close();
               }
           }
       }
Posted
Updated 4-Sep-10 2:49am
v2

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".
 
Share this answer
 
Comments
Katkot 4-Sep-10 10:04am    
Oh yes, I did not notice.
Thanks:)
You can also use AutoFlush = true to ensure that the object writes it properly. :rose:
 
Share this answer
 

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