Click here to Skip to main content
15,896,063 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
this is my code which runs when someone click on save button

C#
Stream save;
            saveFileDialog1.ShowDialog();
            if (saveFileDialog1.ShowDialog() == DialogResult.OK)
            {
                if ((save = saveFileDialog1.OpenFile()) != null)
                {

                    save.Close();
                }
            }


before save.close() i want to write all the text of a richtextbox in the file which i m saving,how can i do that?
Posted

1 solution

Just use this
C#
if (saveFileDialog1.ShowDialog() == DialogResult.OK)
{
  System.IO.File.WriteAllText(saveFileDialog1.FileName,youtTextBox.Text);
}
 
Share this answer
 
v2
Comments
Sweety Khan 24-Aug-11 7:20am    
wOw so easy. but it is giving one error that the file cannot be access. it creates the file but there is nothing written in it.
Prerak Patel 24-Aug-11 7:31am    
Where you are trying to save?
Sweety Khan 24-Aug-11 7:40am    
and also save dialog appears two times. means first time i give name to file, click on save then save dialog again appears and having detail file name eg C:\Users\Asma\Desktop\filename and i again click on save then error comes.
Prerak Patel 24-Aug-11 7:45am    
oops sorry, remove the first line.
Sweety Khan 24-Aug-11 7:50am    
ok now dialog appears one time but same error comes :( that file cannot be access because another process using 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