readyState never complete when using mshtml and UCOMIPersistFile to load HTML from file

G

Gil Schulmann

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;
 
G

Gil Schulmann

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.
 
C

Charles Law

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top