Click here to Skip to main content
15,881,600 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I'm busy writing a text editor and I want the Open & New File Dialog to be able to open a Rich Text File/ or a Doc file,and display the content of the file with the text as it was previously formatted.

when i open previously saved document i either get garbage/ nothing or plain text

Thank you in advance.

Below is my code:

Private Sub Button3_Click(sender As Object, e As EventArgs) Handles mnuOpen.Click

Dim OpenFileDialog1 As New OpenFileDialog
With OpenFileDialog1
If .ShowDialog = DialogResult.OK Then
Dim path As String = .FileName
Dim ReadIt As String = System.IO.File.ReadAllText(path)
TextBox1.Text = ReadIt
End If
End With

End Sub

What I have tried:

Private Sub Button3_Click(sender As Object, e As EventArgs) Handles mnuOpen.Click

Dim OpenFileDialog1 As New OpenFileDialog
With OpenFileDialog1
If .ShowDialog = DialogResult.OK Then
Dim path As String = .FileName
Dim ReadIt As String = System.IO.File.ReadAllText(path)
TextBox1.Text = ReadIt
End If
End With

End Sub
Posted
Comments
Member 15627495 11-Sep-22 16:12pm    
try the RichTextBox control, It's an enhanced textbox , with more capacities
Member 11788039 12-Sep-22 0:53am    
I have tried that but it doesn't work.
Member 15627495 12-Sep-22 1:17am    
to read .doc , you need 'office' resource , but about *.rtf it's easy to have a display on the screen.

try with *.rtf in a first time to fix your textbox
Member 11788039 12-Sep-22 3:20am    
Thank you and what about the formatting of the document I.E (bold/ indent ECT,,
Member 15627495 12-Sep-22 3:21am    
the richtextbox will handle that / the textbox doesn't

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900