Murray Brown
asked on
VB.net RichTextBox File format is not valid
Hi. I am trying to save the contents of a RichTextBox to a .rtf file and reload it, but am getting the error
"VB.net RichTextBox File format is not valid" at the line marked XXXX
Imports System.Windows.Forms
Public Class Form3
Private Sub btnSave_Click(sender As System.Object, e As System.EventArgs) Handles btnSave.Click
SaveMyFile()
End Sub
Public Sub SaveMyFile()
Dim saveFile1 As New SaveFileDialog()
saveFile1.DefaultExt = "*.rtf"
saveFile1.Filter = "RTF Files|*.rtf"
If (saveFile1.ShowDialog() = System.Windows.Forms.Dialo gResult.OK ) _
And (saveFile1.FileName.Length ) > 0 Then
Me.Label1.Text = saveFile1.FileName
RichTextBox1.SaveFile(save File1.File Name, _
RichTextBoxStreamType.Plai nText)
End If
End Sub
Private Sub btnLoad_Click(sender As System.Object, e As System.EventArgs) Handles btnLoad.Click
CreateRichTextBox()
End Sub
Public Sub CreateRichTextBox()
Dim richTextBox1 As New RichTextBox()
richTextBox1.Dock = DockStyle.Fill
'richTextBox1.lo()
richTextBox1.LoadFile("C:\ Users\user \Desktop\v .rtf") 'XXXX
richTextBox1.Find("Text", RichTextBoxFinds.MatchCase )
'richTextBox1.SelectionFon t = New Font("Verdana", 12, FontStyle.Bold)
'richTextBox1.SelectionCol or = Color.Red
richTextBox1.SaveFile("C:\ Users\user \Desktop\v .rtf", RichTextBoxStreamType.Rich Text)
Me.Controls.Add(richTextBo x1)
End Sub
"VB.net RichTextBox File format is not valid" at the line marked XXXX
Imports System.Windows.Forms
Public Class Form3
Private Sub btnSave_Click(sender As System.Object, e As System.EventArgs) Handles btnSave.Click
SaveMyFile()
End Sub
Public Sub SaveMyFile()
Dim saveFile1 As New SaveFileDialog()
saveFile1.DefaultExt = "*.rtf"
saveFile1.Filter = "RTF Files|*.rtf"
If (saveFile1.ShowDialog() = System.Windows.Forms.Dialo
And (saveFile1.FileName.Length
Me.Label1.Text = saveFile1.FileName
RichTextBox1.SaveFile(save
RichTextBoxStreamType.Plai
End If
End Sub
Private Sub btnLoad_Click(sender As System.Object, e As System.EventArgs) Handles btnLoad.Click
CreateRichTextBox()
End Sub
Public Sub CreateRichTextBox()
Dim richTextBox1 As New RichTextBox()
richTextBox1.Dock = DockStyle.Fill
'richTextBox1.lo()
richTextBox1.LoadFile("C:\
richTextBox1.Find("Text", RichTextBoxFinds.MatchCase
'richTextBox1.SelectionFon
'richTextBox1.SelectionCol
richTextBox1.SaveFile("C:\
Me.Controls.Add(richTextBo
End Sub
ASKER
Hi. Thanks. If I specify plain text then will I be able to reload the text as formatted?
How would I change the code?
How would I change the code?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
thanks very much
richTextBox1.LoadFile("C:\