vbnet Code:
Imports System.Text
Imports System.IO
Public Class Form1
Private Function rtf2txt(ByVal Source As String, ByVal Output As String) As Boolean
Dim rbox As New RichTextBox()
Dim sb As New StringBuilder()
Dim sw As StreamWriter
If Not File.Exists(Source) Then
Return False
Else
'Open richtext source file.
rbox.LoadFile(Source, RichTextBoxStreamType.RichText)
'Append text to string builder.
sb.Append(rbox.Text).Replace(vbLf, vbCrLf)
Try
'Create new output file.
sw = New StreamWriter(Output)
'Write plain text
sw.Write(sb.ToString())
'Close file.
sw.Close()
'Clear up
sb = Nothing
Catch ex As Exception
Return False
End Try
End If
'Return good result.
Return True
End Function
vbnet Code:
Private Sub cmdConvert_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdConvert.Click
'Example.
Dim Done As Boolean = rtf2txt("C:\out\data\Document.rtf", "C:\out\data\Document.txt")
'Just show user if convert was done ok.
MessageBox.Show("Convert ok = " & Done.ToString(), "rtf2txt", MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
End Sub