I am having a bit of trouble with converting a string (url) into a Uri. Here is the screenshot of the error:
http://www.imgbomb.com/i/d15/3bk3v.png
Here is the code that is giving me trouble:
Private Sub ComboBox1_Change(sender As Object, e As EventArgs) Handles ComboBox1.TextChanged
Dim myString As String = ComboBox1.Text.ToString()
Me.WebBrowser1.Navigate(New Uri(myString))
End Sub
Is there any reason and ways to fix this?
Here is the full code:
Imports System
Imports System.IO
Imports System.Text
Imports System.Collections.Generic
Public Class Form1
Public SourceCode As String
Dim sb As New StringBuilder()
Dim s As String
Dim StreamWriter
Dim file As System.IO.FileStream
Dim myUri As New Uri(Me.ComboBox1.Text)
Private Sub Button4_Click(sender As Object, e As EventArgs) Handles Button4.Click
WebBrowser1.Navigate(TextBox1.Text)
End Sub
Private Sub Button3_Click(sender As Object, e As EventArgs) Handles Button3.Click
WebBrowser1.Stop()
End Sub
Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
WebBrowser1.GoForward()
End Sub
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
WebBrowser1.GoBack()
End Sub
Private Sub ViewSourceToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles ViewSourceToolStripMenuItem.Click
SourceCode = WebBrowser1.Document.Body.OuterHtml
Form2.Show()
End Sub
Private Async Sub WebBrowser1_DocumentCompleted(sender As Object, e As WebBrowserDocumentCompletedEventArgs) Handles WebBrowser1.DocumentCompleted
ComboBox1.Items.Add(WebBrowser1.Document.Url)
For Each item As Object In ComboBox1.Items
s = s & item.ToString & Environment.NewLine
Next
Dim mydocpath As String = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments)
Dim sb As StringBuilder = New StringBuilder()
sb.Append(s)
Using outfile As StreamWriter = New StreamWriter("history.txt", True)
Await outfile.WriteAsync(sb.ToString())
End Using
End Sub
Private Sub ComboBox1_Click(sender As Object, e As EventArgs) Handles ComboBox1.Click
Try
Dim FILE_NAME As String = "history.txt"
If System.IO.File.Exists(FILE_NAME) = True Then
Dim objReader As New System.IO.StreamReader(FILE_NAME)
Dim Line As String = ""
Do While objReader.Peek() <> -1
Line = objReader.ReadLine()
ComboBox1.Items.Add(Line)
Loop
Else
file = System.IO.File.Create("history.txt")
End If
Catch ex As Exception
MsgBox(ex.Message)
End Try
End Sub
Private Sub ComboBox1_Change(sender As Object, e As EventArgs) Handles ComboBox1.TextChanged
Dim myString As String = ComboBox1.Text.ToString()
Me.WebBrowser1.Navigate(New Uri(myString))
End Sub
End Class