[RESOLVED] load text file into richtextbox
I get this error: "file format is not valid"
can this be fixed? if so, could someone point me the way or give me some more code?
Code:
Dim OpenFile1 As New OpenFileDialog
OpenFile1.Filter = "txt Files (Text Files)|*.txt"
OpenFile1.Title = "Open a Document."
If (OpenFile1.ShowDialog = System.Windows.Forms.DialogResult.OK) Then
RichTextBox1.LoadFile(OpenFile1.FileName)
End If
Re: load text file into richtextbox
Try specifying the file type. If its a plain clear textfile then...
Code:
Me.RichTextBox1.LoadFile("C:\Test.txt", RichTextBoxStreamType.PlainText)
and if its an actual rtf file then....
Code:
Me.RichTextBox1.LoadFile("C:\Test.rtf", RichTextBoxStreamType.RichText)
Re: load text file into richtextbox
Quote:
Originally Posted by RobDog888
Try specifying the file type. If its a plain clear textfile then...
Code:
Me.RichTextBox1.LoadFile("C:\Test.txt", RichTextBoxStreamType.PlainText)
and if its an actual rtf file then....
Code:
Me.RichTextBox1.LoadFile("C:\Test.txt", RichTextBoxStreamType.RichText)
Thanks!!!
that fixed it!!!
Re: [RESOLVED] load text file into richtextbox
Oops, I did a copy/paste error. I didnt change the txt extension if its an actual rtf file. should be Test.rtf. ;)
You could add filters to your filedialog and select case after based upon the extension to determine which type of encoding to apply when loading.
Re: [RESOLVED] load text file into richtextbox
Quote:
Originally Posted by RobDog888
Oops, I did a copy/paste error. I didnt change the txt extension if its an actual rtf file. should be Test.rtf. ;)
You could add filters to your filedialog and select case after based upon the extension to determine which type of encoding to apply when loading.
I caught it.
thanks!
Re: [RESOLVED] load text file into richtextbox
Sorry i couldnt really explain before i was in a rush
the reason i suggested it in the other thread was because i re-created microsoft word lol and i just gave you the code i used for the open function. you can create your own file-type but only your program will be able to read it.
Re: [RESOLVED] load text file into richtextbox
Quote:
Originally Posted by noahssite
Sorry i couldnt really explain before i was in a rush
the reason i suggested it in the other thread was because i re-created microsoft word lol and i just gave you the code i used for the open function. you can create your own file-type but only your program will be able to read it.
ok and thanks!!
Re: [RESOLVED] load text file into richtextbox
why wont this work :(
Quote:
Dim openthisfile As String
openthisfile = (Application.StartupPath & "\files" & sbFile.Text)
If sbFile.Text > "" Then
Me.rtbText.LoadFile(openthisfile, RichTextBoxStreamType.PlainText Or RichTextBoxStreamType.RichText)
End If