well you are specifying to open it as plaintext document all the time.
Best thing to do would be to check the extension of the file, but even then it would not be a 100% proper solution, as you could rename a .txt into a .rtf which *may* cause an error when loading into the RTF. You also dont need to use a stream at all, you can just directly give the filename/path into the LoadFile() method of the RTB control
however if you are still interested, try this:
If OpenFileDialog1.ShowDialog() = Windows.Forms.DialogResult.OK Then
Try
If OpenFileDialog1.FileName.EndsWith(".txt") then
RichTextBox1.LoadFile(OpenFileDialog1.FileName, RichTextBoxStreamType.PlainText)
else if OpenFileDialog1.FileName.EndsWith(".rtf") then
RichTextBox1.LoadFile(OpenFileDialog1.FileName, RichTextBoxStreamType.RichText)
end if
Catch exp As Exception
MessageBox.Show( "An error occurred while attempting to load the file. The error is:" _
+ System.Environment.NewLine + exp.ToString() + System.Environment.NewLine)
End Try
does this help
|