WebBrowser control problems (Encoding & XHTML pages)
I am really starting to hate this control, it seems that some small task are almost impossible to do. I have looked into alternative but did not find anything useful.
I am working on a small application to edit eBooks. I am using the WebBrowser Control to preview the html files.
At First I tried really hard to have no Temp files, so I did it all in Memory with Streams, Modifying the html to include the images Encoded in Base64 and including the CSS directly in the Html. The problem with this is that large image are not displayed correctly, and it forces the user to have IE8 at a minimum.
I looked for other libraries, like a Chrome or Firefox Engine, but both are too big to be of use (11 Meg only for a preview when my app is 500k small).
I then resigned myself to just use temp files, so I would have better compatibility and less problems, with CSS and Images.
The Problem I have is that some file (on some Computer) have the wrong encoding detected (windows-1252), which causes some non-English character to be wrongly displayed. I want them to be forced to UTF-8. If I take the file and encode the text with StreamReader to UTF8 and feed them to DocumentText Property, I loose all the images and formating.
public frmPreview(string filename, string Chapter)
{
InitializeComponent();
string Path = Variables.TempFolder + "\\" + Utils.GetFilePathInsideZip(filename);
webBrowser1.Navigate(Path);
webBrowser1.Document.Encoding = "utf-8";
this.Text = Chapter;
}
1 - How can I force the encoding of the page, Regardless of Computer settings?
Please consider that the Images and CSS are important and I can't see a way To have both my images and the right encoding, because once the text is loaded (with Navigate), it cannot be changed. But if I don't use Navigate it cannot see or Find the CSS and Images.
Also when Navigating to XHTML Files, they are trying to be opened outside of the App (inside the default Windows Browser). At First when using my only Streams I did not have any problems viewing the files.
2 - How can I force the XHTML开发者_运维技巧 files to be opened inside the control?
精彩评论