How To Navigate Multiple Site In WebBrowser

Started by vasanth, Dec 27, 2008, 10:33 PM

Previous topic - Next topic

vasanth

Hi Acumens,

i have a problem in my application,

actually i want to navigate multiple site url in my projects using webbrowser.

the problem is when i try to do a loop. only one site will navigate.....



Thanks in Advance.....
- Proud to be an Acumen -
The think i like most at IT Acumens is,

There approach towards making everyone an Acumen. :)

magesh.p

#1
Hi Vasanth,

Try This Code....

Private Sub BtnNav_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnNav.Click

        Dim url As Integer = urllist.Items.Count
        For x As Integer = 0 To url - 1

            Dim durl As String = urllist.Items(x)
            urllist.SelectedItem = urllist.Items(x)

            WBrowser.Navigate(durl)

        Next
    End Sub


    Private Sub WBrowser_DocumentCompleted(ByVal sender As System.Object, ByVal e As System.Windows.Forms.WebBrowserDocumentCompletedEventArgs) Handles WBrowser.DocumentCompleted

        Dim gcollection As HtmlElementCollection = WBrowser.Document.GetElementsByTagName("img")

        If gcollection.Count <> 0 Then
            ListBox1.Items.Add(urllist.SelectedItem)
        End If


    End Sub
- An Proud Acumen -

vasanth

Hi Magesh,

Try This Code, Its not Working Properly...



- Proud to be an Acumen -
The think i like most at IT Acumens is,

There approach towards making everyone an Acumen. :)

VelMurugan

Hi Vasanth,

The loop you have will navigate to all of the sites - but will only raise the DocumentCompleted event on the last Url as the other navigates will be overwriten.

Post Your Code Please..

vasanth

#4
Hi Guys,

here is my code, I need correct result... Help Me....

Public Urls As List(Of String)
    Public UrlPosition As Integer

Private Sub BtnSend_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtnSend.Click
    ' Initialise the list object and position
        Urls = New List(Of String)
        UrlPosition = 0
        Dim i As Integer

        ' Add the contents of the listbox to the arraylist
        For i = 0 To ListBox1.Items.Count - 1
            Urls.Add(ListBox1.Items(i))
        Next
        If ListBox1.Items.Count <> 0 Then
            WebBrowser1.Navigate(Urls(UrlPosition))
        Else
            Me.Close()
        End If

End Sub

Private sub NextUrl()
     ' Is this a valid navigation
         If UrlPosition <= Urls.Count - 1 Then
            ' It is, so perform the navigate
            WebBrowser1.Navigate(Urls(UrlPosition))
        End If
End Sub

Private Sub WebBrowser1_DocumentCompleted(ByVal sender As System.Object, ByVal e As System.Windows.Forms.WebBrowserDocumentCompletedEventArgs) Handles WebBrowser1.DocumentCompleted

       ' Move to the next Url
    NextUrl()

End Sub

- Proud to be an Acumen -
The think i like most at IT Acumens is,

There approach towards making everyone an Acumen. :)

VelMurugan

Hi Vasanth,

Your Code Is Correct, Only The Line Where Incrementing Is Missed

Private sub NextUrl()
     ' Is this a valid navigation
         UrlPosition = UrlPosition + 1
         If UrlPosition <= Urls.Count - 1 Then
            ' It is, so perform the navigate
            WebBrowser1.Navigate(Urls(UrlPosition))
        End If
End Sub

vasanth

Hi Velmurugan,

Thanks for your help,

Now my code working properly.

Great Forum  :agree  :acumen


- Proud to be an Acumen -
The think i like most at IT Acumens is,

There approach towards making everyone an Acumen. :)