T
Tony Johansson
Hello!
I have a TextBox control in my program which is called txtBox.
When I write something in the TextBox control and click on the SaveAsMeny
item this
event handler SaveAsToolStripMenuItem_Click is called.
My problem is that nothing will be written to the filename that was chosen
in the saveFileDialog.
Does anybody have any idea why the file is empty after having written the
contens in the TextBox to the file.
This is done by using
new StreamWriter(fs).Write(txtBox.Text);
in the SaveFile method shown below.
private void SaveAsToolStripMenuItem_Click(object sender, EventArgs e)
{
if (saveFileDialog.ShowDialog() == DialogResult.OK)
{
SaveFile(saveFileDialog.FileName);
}
}
private void SaveFile(string fileName)
{
try
{
using (FileStream fs = new FileStream(fileName, FileMode.Create))
{
new StreamWriter(fs).Write(txtBox.Text);
}
}
catch (Exception)
{
}
}
//Tony
I have a TextBox control in my program which is called txtBox.
When I write something in the TextBox control and click on the SaveAsMeny
item this
event handler SaveAsToolStripMenuItem_Click is called.
My problem is that nothing will be written to the filename that was chosen
in the saveFileDialog.
Does anybody have any idea why the file is empty after having written the
contens in the TextBox to the file.
This is done by using
new StreamWriter(fs).Write(txtBox.Text);
in the SaveFile method shown below.
private void SaveAsToolStripMenuItem_Click(object sender, EventArgs e)
{
if (saveFileDialog.ShowDialog() == DialogResult.OK)
{
SaveFile(saveFileDialog.FileName);
}
}
private void SaveFile(string fileName)
{
try
{
using (FileStream fs = new FileStream(fileName, FileMode.Create))
{
new StreamWriter(fs).Write(txtBox.Text);
}
}
catch (Exception)
{
}
}
//Tony