This is a migrated thread and some comments may be shown as answers.

[Solved] Loading Content From An HTML file

1 Answer 207 Views
Editor
This is a migrated thread and some comments may be shown as answers.
John Reid
Top achievements
Rank 1
John Reid asked on 28 Jul 2009, 01:44 AM
Hi -

I am loading the editor content from an HTML file with the following code:

Private Sub LoadEditor(ByVal File As String)

 

 

Dim sr As System.IO.StreamReader

 

 

Dim fi As New System.IO.FileInfo(File)

 

 

Dim strContents As String = ""

 

 

If System.IO.File.Exists(File) Then

 

sr = System.IO.File.OpenText(File)

strContents += sr.ReadToEnd()

Editor.Content = strContents

sr.Close()

 

Else

 

 

End If

 

 

End Sub



I seem to get a few errors that I can't figure out:

1. In the HTML there is a link with a query string. e.g. 
<A href="http://www.abc.com/Default.aspx?id=118&cost=WR1841" target=_blank>
The Editor converts it to:
<A href="http://www.abc.com/Default.aspx?id=118&amp;cost=WR1841" target=_blank>

2. There are special characters like ®
The editor just displays a 

Any help will be appreciated


 



 

 

1 Answer, 1 is accepted

Sort by
0
Rumen
Telerik team
answered on 30 Jul 2009, 08:04 AM
Hi John,

Straight to the points:

1) It is the browser's editing engine itself that changes the ampersand to &amp; in this scenario. What you can do is to use a custom content filter that will change it back.
Please check the following KB that shows how to create and use such filter:
http://www.telerik.com/support/kb/aspnet-ajax/editor/converting-unicode-symbols-to-numeric-html-entities-using-a-content-filter.aspx

For example you can use the following regex for the replacement (code is based on the KB)
newContent = content.replace(/&amp;/gi, "&;");    

2) This is an encoding problem due to that the file content is not saved with Unicode (UTF-8) formatting.
You should make sure that the file is saved with Encoding.UTF8, e.g.

Protected Sub Button1_Click1(ByVal sender As Object, ByVal e As EventArgs)
            Using externalFile As New StreamWriter(Me.MapPath(path), False, Encoding.UTF8)
                externalFile.Write(RadEditor1.Content)
            End Using
End Sub


Best regards,
Rumen
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
Tags
Editor
Asked by
John Reid
Top achievements
Rank 1
Answers by
Rumen
Telerik team
Share this question
or