OpenFileDialog openText = new OpenFileDialog();
                openText.DefaultExt = "txt";
                         if (openText.ShowDialog() == DialogResult.OK)
                         {
                            
                            richTextBox1.LoadFile(openText.FileName,RichTextBoxStreamType.RichText);  
 
                        }运行报错  说文件格式不正确!

解决方案 »

  1.   

    richTextBox1.LoadFile(openText.FileName, RichTextBoxStreamType.PlainText);
      

  2.   

    MSDN的标准写法public void LoadMyFile()
    {
       // Create an OpenFileDialog to request a file to open.
       OpenFileDialog openFile1 = new OpenFileDialog();   // Initialize the OpenFileDialog to look for RTF files.
       openFile1.DefaultExt = "*.rtf";
       openFile1.Filter = "RTF Files|*.rtf";   // Determine whether the user selected a file from the OpenFileDialog.
       if(openFile1.ShowDialog() == System.Windows.Forms.DialogResult.OK &&
          openFile1.FileName.Length > 0) 
       {
          // Load the contents of the file into the RichTextBox.
          richTextBox1.LoadFile(openFile1.FileName);
       }
    }