Writing text box content to a file....

Joined
Jan 10, 2007
Messages
43,898
Location
In The Machine
Hello all,

I'm new here so please bear with me.* I've been writing a program that I need to store the contents of a text box in a file.* The code is pasted here.* I'm not sure what I'm doing wrong.* (I've only been doing c# for 3 months....)

Thanks

Emyr

===== [ Code snippet ] =====


******* private void saveAsToolStripMenuItem_Click(object sender, EventArgs e)
******* {
*********** SaveFileDialog save = new SaveFileDialog();***********
*********** save.Filter = "Expression Files(*.exp)|*.exp";
*********** try
*********** {
*************** if (save.ShowDialog() == DialogResult.OK)
*************** {
******************* string y;
******************* y = textBox1.Text;
******************* //MessageBox.Show(y);
******************* FileStream aFile = new FileStream(save.FileName, FileMode.CreateNew);
******************* sw = new StreamWriter(save.FileName);
******************* //MessageBox.Show("File Saved");
******************* sw.WriteLine(y);
******************* //saveFile(save.FileName);
*************** }
*********** }
*********** catch (ArgumentException)
*********** {
*************** // Do nothing.* User canceled the operation
*********** }
*********** catch (IOException)
*********** {
*************** MessageBox.Show("There was an error in writing the file");
*********** }




More...

View All Our Microsoft Related Feeds
 
Back
Top