• 0

[C#] How Can I Open a Html File ..........?


Question

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

1 answer to this question

Recommended Posts

  • 0

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

This topic is now closed to further replies.
  • Recently Browsing   0 members

    • No registered users viewing this page.