1

I know that this is a common question but I couldnt find an answer for my problem. I am currently working on a HTML editor. With one button click you can change from the webbrowser view to the textview. If I press the button again the webbrowser will be displayed again with the HTML code. But I can also change the code manually in text mode and if I do that the code will be displayed wrong. For example: If I write something like this:

Ö Ä Ü

and I change something it will show this:

Ö Ä Ü

I already tried this:

byte[] bytes = Encoding.Default.GetBytes(mytextbox.Text);
string htmlcode = Encoding.UTF8.GetString(bytes);

and this:

 HttpUtility.HtmlDecode

but that didnt work. I hope you can help me.

EDIT:

I have a WPF WebBrowser where I can edit my code with mshtml. If I write something like this:

Ö Ä U

and I change to the text view with this code:

mytextbox.Text = doc.body.outerHTML;

the HTML code shown in the textbox:

<BODY>Ö Ä Ü</BODY>

the textbox is ReadOnly if you want to edit this you need to press another button. If I edit the text and change to the browserview again currently with this code:

if (myWebBrowser != null)
{
   myWebBrowser.Dispose();
   browsergrid.Children.Remove(myWebBrowser);
}
if (doc != null)
{
   doc.clear();
}
myWebBrowser = new WebBrowser();
browsergrid.Children.Add(myWebBrowser);
myWebBrowser.NavigateToString(mytextbox.Text);
doc = myWebBrowser.Document as HTMLDocument;
doc.designMode = "On";

the Browser displays this:

Ö Ä Ü

nicoh
  • 374
  • 2
  • 12

2 Answers2

3

Fixed it by myself. Here the solution if somebody wants to know it:

I changed my default document string from

<html><body></body></html>

to

<html><meta http-equiv='Content-Type' content='text/html;charset=UTF-8'><body></body></html>

I changed my TextBox to a RichTextBox because the code would be more clear and I was only showing the body of my HTML code with this:

mytextbox.Text = doc.body.outerHTML;

and I edited it to see the whole HTML code:

myRichTextBox.Document.Blocks.Clear();
myRichTextBox.Selection.Text= doc.documentElement.innerHTML;

The code to load the html code back to the browser:

string htmlcode = new TextRange(myRichTextBox.Document.ContentStart, myRichTextBox.Document.ContentEnd).Text;
myWebBrowser.NavigateToString(htmlcode);

Thanks for your answers!

nicoh
  • 374
  • 2
  • 12
2

You can use html codes for those characters. These codes can be found in This Link.

In your case:

replace Ö with &Ouml ; //remove space before ";"

replace Ä with &Auml ; //remove space before ";"

replace Ü with &Uuml ; //remove space before ";"

Community
  • 1
  • 1
ReshaD
  • 936
  • 2
  • 18
  • 30