# .NET and More > WPF, WCF, WF >  [RESOLVED] RichTextBox Issues

## technipixel

Hi,
I made a FontViewer program using WPF (See screen below)

Here are the issues...
1) When loading a saved RTF file, I am getting a bunch of font names appended at the end of my text that IS NOT VISIBLY IN THE RTF file
2) After loading file into RTB, I can not longer change the font size

Here is my saving and loading code for the RTF file.



```
'SAVE RTF
If File.Exists(DemoRTFFile) Then
    fs = New FileStream(DemoRTFFile, FileMode.Open, FileAccess.Write)
        Using fs
            Dim RTBText As New TextRange(rtfEditor.Document.ContentStart, rtfEditor.Document.ContentEnd)
            RTBText.Save(fs, DataFormats.Rtf)
        End Using
End If

'Load RTF
If File.Exists(DemoRTFFile) Then
    fs = New FileStream(DemoRTFFile, FileMode.Open, FileAccess.Read)
       Using fs
           Dim RTBText As New TextRange(rtfEditor.Document.ContentStart, rtfEditor.Document.ContentEnd)
           RTBText.Load(fs, DataFormats.Rtf)
        End Using
End If
```

Any insight would be appreciated

----------


## comprar

I have the same problem. Please write did you find the solution? If yes, share it.

----------


## technipixel

> I have the same problem. Please write did you find the solution? If yes, share it.


Actually.... I finished the app but did not fix that problem because I decide I wasn't going to load an RTF.
I commented out the loading code.

Maybe this week sometimes I can figure out why it loads with those extra characters and let you know.

----------


## technipixel

I did another test with a new project and I got all those font names when I loaded the same old RTF file as above.

But, when I created a new RTF file altogether I didn't get those font names at the end.

So, I am assuming that something is weird about the RTF file I used a while back.

Here is my updated load and save code....



```
Imports System.IO

Class MainWindow

    Dim fs As FileStream


    Private Sub button1_Click(sender As Object, e As RoutedEventArgs) Handles button1.Click
        Dim dlg As New Microsoft.Win32.SaveFileDialog
        Dim filename As String = "myrftfile"
        dlg.InitialDirectory = Path.GetDirectoryName(filename)
        dlg.FileName = Path.GetFileName(filename)
        dlg.DefaultExt = ".rtf" ' Default file extension
        dlg.Filter = "RTF Files (.rtf)|*.rtf" ' Filter files by extension

        ' Show open file dialog box
        Dim result? As Boolean = dlg.ShowDialog()

        ' Process open file dialog box results
        If result = True Then

            ' Open document
            filename = dlg.FileName

            fs = New FileStream(filename, FileMode.Create, FileAccess.Write)
            Using fs
                Dim RTBText As New TextRange(rtfEditor.Document.ContentStart, rtfEditor.Document.ContentEnd)
                RTBText.Save(fs, DataFormats.Rtf)
            End Using

        End If
    End Sub

    Private Sub button_Click(sender As Object, e As RoutedEventArgs) Handles button.Click
        'Load RTB with text from RTF file
        'If File.Exists(DemoRTFFile) Then
        '    fs = New FileStream(DemoRTFFile, FileMode.Open, FileAccess.Read)
        '    Using fs
        '        ' Create a TextRange that comprises the start and end points of the RichTextBox text
        '        Dim RTBText As New TextRange(rtfEditor.Document.ContentStart, rtfEditor.Document.ContentEnd)
        '        RTBText.Load(fs, DataFormats.Rtf)
        '    End Using
        'End If

        Dim dlg As New Microsoft.Win32.OpenFileDialog
        Dim filename As String = "myrftfile"
        dlg.InitialDirectory = Path.GetDirectoryName(filename)
        dlg.FileName = Path.GetFileName(filename)
        dlg.DefaultExt = ".rtf" ' Default file extension
        dlg.Filter = "RTF Files (.rtf)|*.rtf" ' Filter files by extension

        ' Show open file dialog box
        Dim result? As Boolean = dlg.ShowDialog()

        ' Process open file dialog box results
        If result = True Then

            rtfEditor.Document.Blocks.Clear()
            rtfEditor.Focus()

            ' Open document
            filename = dlg.FileName

            fs = New FileStream(filename, FileMode.Open, FileAccess.Read)
            Using fs
                Dim RTBText As New TextRange(rtfEditor.Document.ContentStart, rtfEditor.Document.ContentEnd)
                RTBText.Load(fs, DataFormats.Rtf)
            End Using

        End If
    End Sub

    Private Sub button2_Click(sender As Object, e As RoutedEventArgs) Handles button2.Click
        'load default text 
        rtfEditor.AppendText("!" & Chr(34) & "#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}~""*¡¢£¤¥¦§¨©ª«¬*®¯°±²³´µ¶·¸¹º»¼½¾¿ÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖ×ØÙÚÛÜÝÞßàáâãäåæçèéêëìíîïðñòóôõö÷øùúûüýþÿ")
    End Sub


End Class
```

----------

