|
Did you know . . . that when MS Word saves a file as RTF it saves a TON of junk in the file header that isn't needed for the file and that only MS Word uses? Well . . . there's a really easy way of cleaning up those files. A long, long time ago, I discovered that loading one of these "dirty" RTF files into a RTB (RichTextBox) and then re-saving that file FROM the RTB would do the trick? Yeah, I know. You already knew about this but I still think it's cool.
Here's my code snippet that shows how I do this: Dim oRTB As New RichTextBox Dim oOpen As New OpenFileDialog Dim i As Integer
With oOpen .Filter = "Rich Text Files (*.rtf)|*.rtf" .FilterIndex = 0 .RestoreDirectory = True .Multiselect = True If .ShowDialog = DialogResult.OK Then For i = .FileNames.GetLowerBound(0) To .FileNames.GetUpperBound(0) oRTB.LoadFile(.FileNames(i)) oRTB.SaveFile(.FileNames(i)) Next End If .Dispose() End With oRTB.Dispose()
MessageBox.Show("The " & i & " rich text files (RTF) you selected are now clean.", "RTF Clean Complete", MessageBoxButtons.OK, MessageBoxIcon.Information) |