求助:textbox保存后文本里面没有内容
如题,保存后文本文档里面没有东西,新手请教高手们如何解决,我的代码如下private void SaveFile_Click(object sender, EventArgs e)
{
Stream myStream;
string fileName = "Untitled";
SaveFileDialog saveFileDialog1 = new SaveFileDialog();
saveFileDialog1.InitialDirectory = "c:\\";
saveFileDialog1.Filter = "txt files (*.txt)|*.txt|All files (*.*)|*.*";
saveFileDialog1.FilterIndex = 2;
saveFileDialog1.RestoreDirectory = true;
if (saveFileDialog1.ShowDialog() == DialogResult.OK)
{
if ((myStream = saveFileDialog1.OpenFile()) != null)
{
try
{
fileName = saveFileDialog1.FileName;
Stream stream = File.OpenWrite(fileName);
StreamWriter writer = new StreamWriter(fileName,false,Encoding.Default);
writer.Write(tbUserProgram.Text);
writer.Close();
stream.Close();
myStream.Close();
}
catch
{ }
}
}
}