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

simpleonline1234

Junior Member
Joined
Jan 26, 2010
Messages
170
Reaction score
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
 
I dont quite understand what you are talking about.
 
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!
 
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

Private Sub wc_DocumentCompleted(ByVal sender As Object, ByVal e As System.Windows.Forms.WebBrowserDocumentCompletedEventArgs) Handles wc.DocumentCompleted wc.ScriptErrorsSuppressed = True



Dim doc As HtmlDocument = wc.Document
Dim link As HtmlElement
Dim links As HtmlElementCollection = wc.Document.All


With wc.Document.Body
If .InnerHtml.Contains("Incomplete title or text") Then
statusMsg = "False|Incomplete title or text"
Me.Close()
End If
 
Back
Top