Hi.
I am trying to load an HTML file into htmlDoc using c#. I see that the
document does not load, but I can not understand where am I wrong. Any
help ?
My Code:
class CFileHandler{
public delegate void
HTMLDocumentEvents2_onreadystatechangeEventHandler(object
sender,EventArgs e)
public void GetXml(FileInfo file){
HTMLDocumentClass doc = new HTMLDocumentClass();
UCOMIPersistFile pf = (UCOMIPersistFile)doc;
pf.Load(file.FullName, 0);
// HTMLDocumentEvents2_Event htmlEvents =
(HTMLDocumentEvents2_Event)doc;
// htmlEvents.onreadystatechange += new
HTMLDocumentEvents2_onreadystatechangeEventHandler();
while( doc.body == null ){
System.Threading.Thread.Sleep(100);
Console.WriteLine(doc.readyState);
}
}
I am using:
using System;
using System.IO;
using System.Collections;
using System.Xml;
using System.Web;
using mshtml;
using System.Runtime.InteropServices;
Gil Schulmann - 30 Sep 2003 09:12 GMT
this option will work:
string pageHtmlString = GetHtmlString(file.FullName);
object[] oPageText = {pageHtmlString};
doc = new HTMLDocumentClass();
IHTMLDocument2 oDoc = (IHTMLDocument2)doc;
oDoc.write(oPageText);
But I want to use :
HTMLDocumentClass doc = new HTMLDocumentClass();
UCOMIPersistFile pf = (UCOMIPersistFile)doc;
pf.Load(file.FullName, 0);
Gil.
Charles Law - 30 Sep 2003 10:49 GMT
Hi Gil
I have just converted your code to VB.NET (that is what I am most familiar
with) and it worked fine:
<code>
Dim doc As mshtml.HTMLDocumentClass = New mshtml.HTMLDocumentClass
Dim pf As UCOMIPersistFile = DirectCast(doc, UCOMIPersistFile)
pf.Load("o:\projects\workflow\webpages\tabletest.htm", 0)
Do Until doc.readyState = "complete"
Application.DoEvents()
Loop
</code>
readyState goes to "loading", and then to "complete".
Are you able to try something similar in your preferred language?
HTH
Charles
> this option will work:
>
[quoted text clipped - 11 lines]
>
> Gil.