Simple application with opening webpage in VB

316 Views Asked by At

I would like to create simple exe app in VB, which will open default browser with specified page. I have this code

Public Class Form1
Private Sub Label1_Click(sender As Object, e As EventArgs) Handles Label1.Click

End Sub

Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
    System.Diagnostics.Process.Start("www.google.com")
End Sub  End Class

If I click on the button I get error message:

System.ComponentModel.Win32Exception: System cannot find this file

Could someone help me where is the problem? Or is there any other approach how to open webpage?

2

There are 2 best solutions below

0
Lorenzo Martini On

"System cannot find this file" means that your system is not reading the URL as one and it's trying to get the resource at the local path: "www.google.com" which obviously doesn't exist. Check this link because the issue seems to be the same.

0
Vector On

Here in an application I call Best Links is the process I use to view URL's.
It works by storing website URL links in a SQLite Database (DB).
The DB also stores the Site Name and the Last Visit Date.To view the site the user just clicks on the DB entry displayed in DataGridView. Screen Shot Below. And the code that opens the link in what ever your default browser is.

 Private Sub dgvLinks_CellClick(sender As System.Object, e As System.Windows.Forms.DataGridViewCellEventArgs) Handles dgvLinks.CellClick

    selRow = e.RowIndex

    If e.RowIndex = -1 Then
        gvalertType = "4"
        frmAlert.ShowDialog()
        Exit Sub
    End If

    Dim row As DataGridViewRow = Me.dgvLinks.Rows(e.RowIndex)
    If row.Cells(2).Value Is Nothing Then
        gvalertType = "5"
        frmAlert.ShowDialog()
        Return
        Exit Sub
    ElseIf gvTxType = "View" Then
        webPAGE = row.Cells(2).Value.ToString()
        siteID = CInt(row.Cells(0).Value.ToString())

        UpdateSiteData()

        Process.Start(webPAGE)

Data Grid View

If you would like the complete code or and exe file let me know and I will add it to my GitHub repository code will be a ZIP file.