Loading HTMLDocument from a string

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Frank Perugini

    #1

    Loading HTMLDocument from a string

    Hello All,

    I have an HTML document stored in a database field and wish to load
    and manipulate it with inline C# code like the following:

    WebBrowser webControl = new WebBrowser();
    webControl.Docu mentText = htmlstringfromd b;
    //Need to wait for DocumentComplet ed event to be sure page is loaded.
    HtmlDocument doc = webControl.Docu ment;
    string test = doc.Body.ToStri ng();

    The problem is that as indicated in the comment line above, it appears
    if you try to set the DocumentText property of the WebBrowser control
    with HTML, you need to wait for the DocumentComplet ed event to be sure
    it's loaded before trying to access the elements.

    Does anyone know any way to wait for the document to load inline?

    -Frank

  • Frank Perugini

    #2
    Re: Loading HTMLDocument from a string

    On Feb 25, 9:03 pm, "Frank Perugini" <perug...@yahoo .comwrote:
    Hello All,
    >
    I have an HTML document stored in a database field and wish to load
    and manipulate it with inline C# code like the following:
    >
    WebBrowser webControl = new WebBrowser();
    webControl.Docu mentText = htmlstringfromd b;
    //Need to wait for DocumentComplet ed event to be sure page is loaded.
    HtmlDocument doc = webControl.Docu ment;
    string test = doc.Body.ToStri ng();
    >
    The problem is that as indicated in the comment line above, it appears
    if you try to set the DocumentText property of the WebBrowser control
    with HTML, you need to wait for the DocumentComplet ed event to be sure
    it's loaded before trying to access the elements.
    >
    Does anyone know any way to wait for the document to load inline?
    >
    -Frank
    I found it myself. For others interested:

    WebBrowser webControl = new WebBrowser();
    webControl.Docu mentText = htmlstringfromd b;

    do
    {
    Application.DoE vents();
    } while (webControl.Rea dyState != WebBrowserReady State.Complete) ;

    string test = webControl.Docu ment.Body.Inner Html;

    -Frank

    Comment

    Working...