Results 1 to 12 of 12

Thread: [RESOLVED] WebBrowser1.DocumentText = ???

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    May 2001
    Posts
    525

    Resolved [RESOLVED] WebBrowser1.DocumentText = ???

    I've put my HTML into an array then did the following:

    Code:
     Dim j As Integer
            WebBrowser1.DocumentText = ""
            While arrCard(j) <> "+++END+++"
                'objStreamWriter.WriteLine(arrCard(j))
                WebBrowser1.DocumentText += arrCard(j)
                j += 1
            End While
    
            WebBrowser1.Update()
    However, nothing happens in the WebBrowser1 control. DocumentText still says "<HTML></HTML> rather than the code I just gave it. It doesn't display the HTML. The only way I can get it to display anything is if I set the URL to a file before I run the program.

    Any ideas?

  2. #2
    Registered User nmadd's Avatar
    Join Date
    Jun 2007
    Location
    U.S.A.
    Posts
    1,676

    Re: WebBrowser1.DocumentText = ???

    Try putting your HTML into a string variable inside of your loop and then set your WebBrowser's DocumentText to that string after the loop.

    For example
    vb.net Code:
    1. ' Put HTML in my WebBrowser.
    2.         Dim s As String = String.Empty
    3.         For i As Integer = 0 To 10
    4.             s += "Hi"
    5.         Next i
    6.         Me.WebBrowser1.DocumentText = s

  3. #3
    Frenzied Member stimbo's Avatar
    Join Date
    Jun 2006
    Location
    UK
    Posts
    1,739

    Re: WebBrowser1.DocumentText = ???

    Without seeing the original text it's hard to say for sure but there's probably a better way of assigning the content rather than looping through.

    Out of interest, how does the text get placed into an array in the first place? Where does it originate from?
    Stim

    Free VB.NET Book Chapter
    Visual Basic 2005 Cookbook Sample Chapter

  4. #4

    Thread Starter
    Fanatic Member
    Join Date
    May 2001
    Posts
    525

    Re: WebBrowser1.DocumentText = ???

    The array gets built as such:

    Code:
           arrCard(i) = "<!DOCTYPE html PUBLIC '-//W3C//DTD XHTML 1.0 Transitional//EN' 'http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd'>"
            i += 1
            arrCard(i) = "<html xmlns='http://www.w3.org/1999/xhtml'>"
            i += 1
            arrCard(i) = "<head>"
    nmadd: I tried that and it didn't work.

  5. #5
    Frenzied Member stimbo's Avatar
    Join Date
    Jun 2006
    Location
    UK
    Posts
    1,739

    Re: WebBrowser1.DocumentText = ???

    Can you post a link to the html file that it's taken from?

    What I really mean is that if there's a html document out there and you are feeding it 1 line at a time by hand then you might simply be able to create your array very easily by splitting by new line so you could avoid all that repetition. I mean, how long does that code go on for? If it was a large page i would imagine a great deal longer...

    Maybe use a WebClient to download the string, parse the file and then simply loop the array. Just trying to find out about the background of it.
    Stim

    Free VB.NET Book Chapter
    Visual Basic 2005 Cookbook Sample Chapter

  6. #6
    Registered User nmadd's Avatar
    Join Date
    Jun 2007
    Location
    U.S.A.
    Posts
    1,676

    Re: WebBrowser1.DocumentText = ???

    Really? Because I can get something like this to work:
    vb.net Code:
    1. ' Fill my WebBrowser.
    2.         Dim s As String = String.Empty
    3.         For i As Integer = 0 To 100
    4.             s += ary(i)
    5.         Next i
    6.  
    7.         Me.WebBrowser1.DocumentText = s

    but not this:
    vb.net Code:
    1. ' Fill my WebBrowser.
    2.         Dim s As String = String.Empty
    3.         For i As Integer = 0 To 100
    4.             Me.WebBrowser1.DocumentText += ary(i)
    5.         Next i

  7. #7

    Thread Starter
    Fanatic Member
    Join Date
    May 2001
    Posts
    525

    Re: WebBrowser1.DocumentText = ???

    stimbo: it's not a file. I'm building the HTML in that array.

    nmadd: i hear the internet explorer "click" noise, but that's it. the page stays blank and documentext still = "<HTML></HTML>"

  8. #8
    Frenzied Member stimbo's Avatar
    Join Date
    Jun 2006
    Location
    UK
    Posts
    1,739

    Re: WebBrowser1.DocumentText = ???

    Without checking if the content is okay this works perfectly for me:

    vb Code:
    1. Dim arrCard(8) As String
    2. Dim i As Integer = 0
    3.  
    4.         arrCard(i) = "<!DOCTYPE html PUBLIC '-//W3C//DTD XHTML 1.0 Transitional//EN' 'http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd'>"
    5.         i += 1
    6.         arrCard(i) = "<html xmlns='http://www.w3.org/1999/xhtml'>"
    7.         i += 1
    8.         arrCard(i) = "<head>"
    9.         i += 1
    10.         arrCard(i) = "<meta http-equiv=" & "Content-Type" & "content=" & "text/html; charset=ISO-8859-1" & "/>"
    11.         i += 1
    12.         arrCard(i) = "</head>"
    13.         i += 1
    14.         arrCard(i) = "<body>"
    15.         i += 1
    16.         arrCard(i) = "<P>My content <br> Really </P>"
    17.         i += 1
    18.         arrCard(i) = "</body>"
    19.         i += 1
    20.         arrCard(i) = "</html>"
    21.        
    22.         Dim totalContent As String = Nothing
    23.         For j As Integer = 0 To arrCard.Length - 1
    24.             totalContent &= arrCard(j)
    25.         Next
    26.  
    27.         Me.WebBrowser1.DocumentText = totalContent

    Set break points and start stepping through your code and find out where the problem is.
    Stim

    Free VB.NET Book Chapter
    Visual Basic 2005 Cookbook Sample Chapter

  9. #9
    Registered User nmadd's Avatar
    Join Date
    Jun 2007
    Location
    U.S.A.
    Posts
    1,676

    Re: WebBrowser1.DocumentText = ???

    Nuts. I just typed a whole thing up too.
    I'm not sure why your HTML is like this but it works fine here too.

  10. #10

    Thread Starter
    Fanatic Member
    Join Date
    May 2001
    Posts
    525

    Re: WebBrowser1.DocumentText = ???

    I deleted my WebBrowser1 control and re-added it. It works now.

  11. #11
    Registered User nmadd's Avatar
    Join Date
    Jun 2007
    Location
    U.S.A.
    Posts
    1,676

    Re: WebBrowser1.DocumentText = ???

    Glad you got it working. Now you can mark this thread as "Resolved" and let everybody know.

  12. #12

    Thread Starter
    Fanatic Member
    Join Date
    May 2001
    Posts
    525

    Re: [RESOLVED] WebBrowser1.DocumentText = ???

    Done. Thanks guys for your help in troubleshooting.

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