从Richtextbox保存文件 [英] Save File From Richtextbox

查看:74
本文介绍了从Richtextbox保存文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


我如何将Richtextbox的文本保存到document(.doc),但我使用此代码但不起作用:


How i can save the text of richtextbox to document(.doc) i use this code but not working:

private void savebtn_Click(object sender, EventArgs e)
       {
           SaveFileDialog dr = new SaveFileDialog();
           dr.Filter = "Doc File|*.docx";
           if (dr.ShowDialog() == DialogResult.OK)
           {
               rtbWord.SaveFile(dr.FileName);
               MessageBox.Show("save successfully", "Address File : " + dr.FileName, MessageBoxButtons.OK, MessageBoxIcon.Information);
       }


此代码保存文件,但是在执行文档文件时未打开帮助plz.


this code save file but when execute the document file is not open help plz.

推荐答案



请在下面找到将Richtextbox文本保存到.doc文件的代码


Hi ,

Please kindly find the code below that saving the Richtextbox text to .doc file


// Create a SaveFileDialog to request a path and file name to save to.
          SaveFileDialog saveFile1 = new SaveFileDialog();

          // Initialize the SaveFileDialog to specify the RTF extension for the file.
          saveFile1.DefaultExt = "*.doc";
          saveFile1.Filter = "DOC Files|*.doc";

          // Determine if the user selected a file name from the saveFileDialog.
          if (saveFile1.ShowDialog() == System.Windows.Forms.DialogResult.OK &&
             saveFile1.FileName.Length > 0)
          {
              // Save the contents of the RichTextBox into the file.
              richTextBox1.SaveFile(saveFile1.FileName, RichTextBoxStreamType.PlainText);
              MessageBox.Show("save successfully", "Address File : " + saveFile1.FileName, MessageBoxButtons.OK, MessageBoxIcon.Information);

          }



问候,
A.Mandour



Regards,
A.Mandour



这是在Richtextbox中打开Word File(.doc)或Text File(.txt)文件的代码

Hi,
this is Code to Open Word File(.doc) or Text File(.txt) file in Richtextbox

OpenFileDialog openFD = new OpenFileDialog();
        string Chosen_File = "";

        openFD.InitialDirectory = "C:";
        openFD.Title = "Open a Text File";
        openFD.FileName = "";
        openFD.Filter = "Text Files|*.txt|Word Documents|*.doc";
        if (openFD.ShowDialog() != DialogResult.Cancel)
        {
            Chosen_File = openFD.FileName;
            richTextBox1.LoadFile(Chosen_File, RichTextBoxStreamType.PlainText);
        }



问候,
艾哈迈德·曼杜尔(Ahmed Mandour)



Regards,
Ahmed Mandour


这篇关于从Richtextbox保存文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆