1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

VB.NET Created an instance of a form that contains a web browser ~ how do I access the doc

Discussion in 'Visual Basic .NET' started by simpleonline1234, Jul 6, 2012.

  1. simpleonline1234

    simpleonline1234 Junior Member

    Joined:
    Jan 26, 2010
    Messages:
    169
    Likes Received:
    13
    I have create a form with a web browser on it. I create an instance of that form that contains web browser.
    how can I edit the web browser document completed on the new instance?
    Thanks
     
  2. stevie

    stevie Newbie

    Joined:
    Jul 31, 2010
    Messages:
    49
    Likes Received:
    10
    Location:
    UK
    Home Page:
    I dont quite understand what you are talking about.
     
  3. veejayshakthi

    veejayshakthi BANNED BANNED

    Joined:
    Feb 18, 2010
    Messages:
    145
    Likes Received:
    82
    Hello friend,

    kindly pm me, so i can help you...

    Regards
     
  4. openaidbh

    openaidbh BANNED BANNED

    Joined:
    Mar 3, 2012
    Messages:
    328
    Likes Received:
    320
    You can grab the source code of the document with a WebRequest, which is more efficient if you're looking to do something with that- from there just edit it like a normal string.
    Here's the code:
    Code:
    Public Function GetHTML(ByVal URL As String) As String        Dim _PageContent As String = Nothing
            Try
                ' Open a connection
                Dim _HttpWebRequest As System.Net.HttpWebRequest = CType(System.Net.HttpWebRequest.Create(URL), System.Net.HttpWebRequest)
    
    
                ' You can also specify additional header values like the user agent or the referer: (Optional)
                _HttpWebRequest.UserAgent = "Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1)"
                _HttpWebRequest.Referer = "http://www.google.com/"
    
    
                ' set timeout for 10 seconds (Optional)
                _HttpWebRequest.Timeout = 10000
                ' Request response:
                Dim _WebResponse As System.Net.WebResponse = _HttpWebRequest.GetResponse()
    
    
                ' Open data stream:
                Dim _WebStream As System.IO.Stream = _WebResponse.GetResponseStream()
    
    
                ' Create reader object:
                Dim _StreamReader As New System.IO.StreamReader(_WebStream)
    
    
                ' Read the entire stream content:
                _PageContent = _StreamReader.ReadToEnd()
    
    
                ' Cleanup
                _StreamReader.Close()
                _WebStream.Close()
                _WebResponse.Close()
            Catch _Exception As Exception
                ' Error
                Console.WriteLine("Exception caught in process: {0}", _Exception.ToString())
                Return Nothing
            End Try
    
    
            Return _PageContent
        End Function
    Also, if you're looking to put text into a form on the WebBrowser, which it seems like what you might be looking for, you just loop through all the HTML elements til you hit the text area, then use
    Code:
    element.SetAttribute("value","whatevertextyouwishtoinsert")
    Hope this helps!
     
  5. SEOboss

    SEOboss Junior Member

    Joined:
    Nov 23, 2009
    Messages:
    168
    Likes Received:
    38
    Occupation:
    IM
    Location:
    India
    Hi

    Here is one samll code it will be useful for you, if u need more clearance ,post your query

    created a windows form with name web browser , on this form I placed web browser control with name wc