Results 1 to 3 of 3

Thread: [RESOLVED] [2008] Error with MSHTML

  1. #1

    Thread Starter
    New Member
    Join Date
    Jul 2008
    Posts
    12

    Resolved [RESOLVED] [2008] Error with MSHTML

    Hello
    I am trying to grab the current document from the web browser control and converts it to the strong typed mshtml.HTMLDocument class with this function:

    Code:
    Private Function GetCurrentWebDoc() As mshtml.HTMLDocument
            Try
                Return DirectCast(wb.Document, mshtml.HTMLDocument)
            Catch ex As Exception
                Return Nothing
            End Try
        End Function
    But I get the following error:

    Runtime errors might occur when converting 'System.Windows.Forms.HtmlDocument' to 'mshtml.HTMLDocument'.
    coming from the " wb.document ". Did I forget to add a reference ? other than the mshtml that is ?

  2. #2
    PowerPoster stanav's Avatar
    Join Date
    Jul 2006
    Location
    Providence, RI - USA
    Posts
    9,290

    Re: [2008] Error with MSHTML

    You need to get the DomDocument from the Document. Also, there's no HTMLDocument class in mshtml namespace. You probably are after
    the IHTMLDocument (there's also IHTMLDocument2, IHTMLDocument3, IHTMLDocument4 and IHTMLDocument5 calsses that you can use)
    Code:
    Private Function GetCurrentWebDoc() As mshtml.IHTMLDocument
            Try
                Return DirectCast(wb.Document.DomDocument, mshtml.IHTMLDocument)
            Catch ex As Exception
                Return Nothing
            End Try
        End Function
    Last edited by stanav; Jul 18th, 2008 at 08:27 AM.
    Let us have faith that right makes might, and in that faith, let us, to the end, dare to do our duty as we understand it.
    - Abraham Lincoln -

  3. #3

    Thread Starter
    New Member
    Join Date
    Jul 2008
    Posts
    12

    Re: [2008] Error with MSHTML

    looks like it's working but I'll test a few more times before marking this thread as resolved Thank you for your help and the details

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width