I came across an interesting bug that I thought I would share with everyone just in case it is happening to them as well.
When you have saved a file from the editor, if you have a tag, a space and then some text (example below), when saved the 'Â' character appears. This seems to be because a is missing and is rather replaced with the character code 160.
| <td> Some text </td> |
| shows as |
| Â Some text |
When you view the saved file in notepad/ word pad/ visual studio etc. you do not see the character. If you view it in a hex editor, you do.
A problem only arises if you open the saved HTML file, manipulate it and then resave it because then the character code is picked up and acted on (rendered).
Once I managed to track down the problem, the fix was really quite simple, simply:
1. Encode the text to HTML
2. Replace the offending character with a nbsp;
3. Decode from HTML ready for saving or more manipulation.
| string contentData = Server.HtmlEncode(this._RadEditor.Content); |
| contentDatacontentDatacontentData = contentData.Replace(" ", "&nbsp;"); |
| contentData = Server.HtmlDecode(contentData); |
I must stress that this bug only appears after you try and manipulate the document by loading it, manipulating it and resaving it (but it did happen on every machine that we tested it on). If you are viewing your saved documents straight off then this should not be a problem for you.