Save and opening a file using a RichTextBox
Hey ppl
I'm a having a little bit of trouble with opening and saving a file in a richtextbox. I have created the both codes here is the code for both
------------------------------------------------------------------------------------
Open
------------------------------------------------------------------------------------
Code:
Private Sub MenuItemFileOpen_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MenuItemFileOpen.Click
Dim openFile1 As New OpenFileDialog
openFile1.DefaultExt = "*.rtf"
openFile1.Filter = "RTF Files|*.rtf"
If (openFile1.ShowDialog() = System.Windows.Forms.DialogResult.OK) And (openFile1.FileName.Length > 0) Then
RichTextBox1.LoadFile(openFile1.FileName)
End If
End Sub
------------------------------------------------------------------------------------
Save File
------------------------------------------------------------------------------------
Code:
Private Sub MenuItemFileSave_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MenuItemFileSave.Click
Dim saveFile1 As New SaveFileDialog
saveFile1.DefaultExt = "*.rtf"
saveFile1.Filter = "RTF Files|*.rtf"
If (saveFile1.ShowDialog() = System.Windows.Forms.DialogResult.OK) And (saveFile1.FileName.Length) > 0 Then
RichTextBox1.SaveFile(saveFile1.FileName, RichTextBoxStreamType.PlainText)
End If
End Sub
I can open rtf documents made in word but if i save then open rtf files saved in my programm it gives me an error "Invalid File Format" I'm not realy sure where i'm going wrong please can you help?
Thanks
James