将RichText Box的文本保存为文本文件

时间:2014-12-09 13:11:42

标签: c# richtextbox savefiledialog

    private void saveToolStripMenuItem_Click(object sender, EventArgs e)
    {
        SaveFileDialog save_file = new SaveFileDialog();
        if (save_file.ShowDialog() == DialogResult.OK&&save_file.FileName.Length>0)
        {

            save_file.DefaultExt = "txt";
            WriteBox.SaveFile(save_file.FileName,RichTextBoxStreamType.PlainText);
        }
    }

这不起作用,每次打开文件时,计算机都会要求程序选择它既不允许设置默认程序。什么在那里失踪,任何人都有帮助:)

1 个答案:

答案 0 :(得分:0)

使用以下内容:

private void saveToolStripMenuItem_Click(object sender, EventArgs e)
{
    SaveFileDialog save_file = new SaveFileDialog();
    save_file.DefaultExt = "txt";
    save_file.Filter = "Text files (*.txt)|*.txt|All files (*.*)|*.*";

    if (save_file.ShowDialog() == DialogResult.OK&&save_file.FileName.Length>0)
    {
        WriteBox.SaveFile(save_file.FileName,RichTextBoxStreamType.PlainText);
    }
}