Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / .NET Framework / Interop / September 2003

Tip: Looking for answers? Try searching our database.

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

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Gil Schulmann - 29 Sep 2003 11:02 GMT
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.

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.