保存文件对话框 [英] SaveFileDialog
本文介绍了保存文件对话框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
您好,我正在尝试保存TextBox AS txt文件中键入的所有内容..
但是问题是它保存了一个空白的txt文件"! ,
在文本框中键入的所有文本都不会出现在已保存的txt文件中. :S
这里怎么了..
Hello, I''m Trying To SAVE everything typed in the TextBox AS txt file ..
But the problem is that "it saves a blank txt file" !! ,
All the text that typed in the TextBox doesn''t appear in the saved txt file .. !! :S
What is wrong here..
private void button1_Click(object sender, EventArgs e)
{
Stream myStream;
SaveFileDialog saveFileDialog1 = new SaveFileDialog();
saveFileDialog1.Filter = "txt files (*.txt)|*.txt|All files (*.*)|*.*";
saveFileDialog1.FilterIndex = 1;
saveFileDialog1.RestoreDirectory = true;
if (saveFileDialog1.ShowDialog() == DialogResult.OK)
{
if ((myStream = saveFileDialog1.OpenFile()) != null)
{
StreamWriter wText = new StreamWriter(myStream);
wText.Write(" your text");
myStream.Close();
}
}
}
推荐答案
我意识到您已经使用了 ^ ].
请注意页面中间的最后一项-只记得刷新并关闭WText对象....否则就不会写任何东西."
I realised you have used the code off the following article/post[^].
Note the last item towards the of middle the page - "Just remember to Flush and close your WText object.... otherwise nothing gets written".
您也可以使用AutoFlush = true
来确保对象正确写入. :rose:
You can also use AutoFlush = true
to ensure that the object writes it properly. :rose:
这篇关于保存文件对话框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文