Click here to Skip to main content
15,881,248 members
Please Sign up or sign in to vote.
3.00/5 (2 votes)
See more:
In my code I want to save the contents of "txtWritingBox" to a new file.

C#
private void mnuSaveFile_Click(object sender, EventArgs e)
       {

           Stream myStream;
           SaveFileDialog saveFileDialog1 = new SaveFileDialog();



           saveFileDialog1.Filter = "TXT Files (*.txt)|*.txt|CSV files (*.csv)|*.csv";
           saveFileDialog1.FilterIndex = 2;
           saveFileDialog1.RestoreDirectory = true;


           if (saveFileDialog1.ShowDialog() == DialogResult.OK)
           {
               if ((myStream = saveFileDialog1.OpenFile()) != null)
               {
                   // Code to write the stream goes here.


                   myStream.Close();
               }
           }

       }


How to save the file from textbox content
Posted
Comments
KUMAR619 18-Feb-14 8:30am    
Anyone please answer this question
Bernhard Hiller 18-Feb-14 8:44am    
Why do you think we ought to hurry? I'll let you wait now.
Vedat Ozan Oner 18-Feb-14 8:45am    
it is as easy as searching google: http://msdn.microsoft.com/en-us/library/6ka1wd3w%28v=vs.110%29.aspx

try this
File.AppendAllText("Path","Content");

this will resolve your 2 problems.
1) it will create the file if not created.
2) if the file exists it will overwrite it with new content
 
Share this answer
 
Comments
ZurdoDev 18-Feb-14 20:14pm    
+5. The easiest way to do it.

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