Jump to content

Recommended Posts

Posted

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

  • Replies 0
  • Created
  • Last Reply

Top Posters In This Topic

Popular Days

Top Posters In This Topic

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


×
×
  • Create New...