zhwcn Posted September 6, 2005 Share Posted September 6, 2005 How can I open a html file and then show it with a WebBrowser object??? These are some codes I wrote, but didn't work well , please make some changes and let them work . //"str" is a Stream object and "webPage" is a WebBrowser object if(openHtmlFileDialog.ShowDialog() == DialogResult.OK) ? { ? ?if((str = openHtmlFileDialog.OpenFile()) != null) ? ?{ ? ? CMyTabPage myTabPage = new CMyTabPage(); ? ? AxSHDocVw.AxWebBrowser webPage = myTabPage.WebPage; ? ? mshtml.HTMLDocumentClass webPageDoc = (mshtml.HTMLDocumentClass)webPage.Document; ? ? ? ? try ? ? { ? ? ?StreamReader strR = new StreamReader(str); ? ? ?webPageDoc.documentElement.innerHTML = strR.ReadToEnd(); ? ? ?strR.Close(); ? ? } ? ? catch ? ? { ? ? ? ? } ? ?} ? } Link to comment Share on other sites More sharing options...
0 THE BAT Posted September 6, 2005 Share Posted September 6, 2005 You can do it with this simple way if( openHTMLFileDialog.ShowDialog() == DialogResult.OK ) { wb.Navigate( openHTMLFileDialog.FileName ); } and for your code after you read the HTML stream webPageDoc.documentElement.innerHTML = strR.ReadToEnd(); you need to update the WebBrowser // Error wb.Document = webPageDoc; but you can't do this because Document is Read only property may be you can find another way to do it other than my way Link to comment Share on other sites More sharing options...
Question
zhwcn
How can I open a html file and then show it with a WebBrowser object???
These are some codes I wrote, but didn't work well , please make some changes and let them work .
Link to comment
Share on other sites
1 answer to this question
Recommended Posts