Load rtf file with richtextbox stream type Plain Text in vb.net

You can use LoadFile method to load the RichTextBox with data from an existing stream of data.

The data that is loaded into the RichTextBox replaces the whole contents of the RichTextBox control. This will cause the values of the Text and Rtf properties to change. You can use this method to load a file that has been previously opened into a data stream into the control for manipulation.

The following code example show an rtf format file into the RichTextBox control with streams. The example uses the OpenFileDialog class to display a dialog to select the rtf file. After that example loads that rtf file into RichTextBox control named RichTextBox1. If the file is not then, the example code will give the messaage ‘Error in Reading File’.

    Private Sub Button1_Click(ByVal sender As System.Object, _
                              ByVal e As System.EventArgs) Handles Button1.Click
        Dim objFileDlg As New OpenFileDialog()
        objFileDlg.Filter = "All Files|*.*|rtf Files|*.rtf"
        objFileDlg.FilterIndex = 2
        objFileDlg.InitialDirectory = "C:"
        If (objFileDlg.ShowDialog() = DialogResult.OK) Then
                Richtextbox1.Loadfile(objFileDlg.FileName, RichTextBoxStreamType.PlainText)
                MessageBox.Show("Error in Reading File")
            End Try
        End If
    End Sub