在使用C#将文本框的文本写入文件时需要帮助吗? [英] need help in writing the text of a textbox to a file in c#?
本文介绍了在使用C#将文本框的文本写入文件时需要帮助吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
这是我的代码,当有人单击保存"按钮时运行
流保存;
saveFileDialog1.ShowDialog();
如果(saveFileDialog1.ShowDialog()== DialogResult.OK)
{
如果((save = saveFileDialog1.OpenFile())!= 空)
{
save.Close();
}
}
在save.close()之前,我想将一个RichTextBox的所有文本写入要保存的文件中,我该怎么做? br/>
如果(saveFileDialog1.ShowDialog()== DialogResult.OK)
{
System.IO.File.WriteAllText(saveFileDialog1.FileName,youtTextBox.Text);
}
this is my code which runs when someone click on save button
Stream save;
saveFileDialog1.ShowDialog();
if (saveFileDialog1.ShowDialog() == DialogResult.OK)
{
if ((save = saveFileDialog1.OpenFile()) != null)
{
save.Close();
}
}
before save.close() i want to write all the text of a richtextbox in the file which i m saving,how can i do that?
解决方案
Just use this
if (saveFileDialog1.ShowDialog() == DialogResult.OK) { System.IO.File.WriteAllText(saveFileDialog1.FileName,youtTextBox.Text); }
这篇关于在使用C#将文本框的文本写入文件时需要帮助吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文