c# - 在 C# 中创建 RTF 文件的正确方法是什么?

标签 c# winforms file richtextbox save

来自 here 我看到它建议创建一个 RichTextBox 实例,然后使用它的 SaveFile(string path) 方法将文件放到硬盘上:

RichTextBox rtb = new RichTextBox();

rtb.SaveFile(@"\MyFileName.rtf");

它有效,但是,.....这是应该如何完成的,我问它似乎有点老套?如果不是,那么正确的做法是什么。

最佳答案

MSDN documentation说这正是你应该做的。

他们还有下面的例子here :

public void SaveMyFile()
{
   // 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 = "*.rtf";
   saveFile1.Filter = "RTF Files|*.rtf";

   // 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);
   }
}

关于c# - 在 C# 中创建 RTF 文件的正确方法是什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9951159/

相关文章:

c# - 在 .NET 中计算电子邮件的大小

c# - 无法确定 API 响应的格式类型

c# - 使用 NUnit 测试 Windows 窗体逻辑

perl - 在 Perl 中递归打开文件

file - 恢复崇高文本3.0中删除的文件?

c# - 所有使用 C# 开发的应用程序都不是面向对象的?

c# - 使用数组 C# 复制文件的进度条

c# - 每次按下按钮时,如何从字符串的前面连续移动n个字符到末尾?

java - Files.lines 跳过 Java8 中的虚线

c# - 使用 C# 从网站抓取内容