VB.NET check if input is a link

Private Sub btnSave_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)   Handles btnSave.Click
    If txtSubd.Text = "" Then 'If the input is blank
        'DO NOTHING
    Else ' If its not, proceed

        Dim wb As New WebClient

        If wb.DownloadString(txtSubd.Text) = "" Then 'Check if the file entered is blank

            MsgBox("Text file is Blank.", MsgBoxStyle.Exclamation, "Error")

        Else 'If not, proceed

            My.Forms.frmMain.TXTFILE.Text = txtSubd.Text

        End If
    End If

End Sub

So far this works, unless I enter random text. I need this only to run if a online .txt is entered.

I tried System.IO.File.Exists, but thats more local files right? ANy help would be much appreciated. Thanks guys!


Detect if the textbox contains a legit URL (notice the line: If hwresponse.StatusCode = Net.HttpStatusCode.OK, thats the ticket to confirm its not a 404) :

Dim wData as String = WRequest("http://server/sfasnasjnksa", "GET", "")

Function WRequest(URL As String, method As String, POSTdata As String) As String
  Dim responseData As String = ""
    Dim hwrequest As Net.HttpWebRequest = Net.Webrequest.Create(URL)
    hwrequest.Accept = "*/*"
    hwrequest.AllowAutoRedirect = true
    hwrequest.UserAgent = "http_requester/0.1"
    hwrequest.Timeout = 60000
    hwrequest.Method = method
    If hwrequest.Method = "POST" Then
      hwrequest.ContentType = "application/x-www-form-urlencoded"
      Dim encoding As New Text.ASCIIEncoding() 'Use UTF8Encoding for XML requests
      Dim postByteArray() As Byte = encoding.GetBytes(POSTdata)
      hwrequest.ContentLength = postByteArray.Length
      Dim postStream As IO.Stream = hwrequest.GetRequestStream()
      postStream.Write(postByteArray, 0, postByteArray.Length)
    End If
    Dim hwresponse As Net.HttpWebResponse = hwrequest.GetResponse()
    If hwresponse.StatusCode = Net.HttpStatusCode.OK Then
      Dim responseStream As IO.StreamReader = _
        New IO.StreamReader(hwresponse.GetResponseStream())
      responseData = responseStream.ReadToEnd()
    End If
    Catch e As Exception
      responseData = "An error occurred: " & e.Message
    End Try
  Return responseData
End Function

Need Your Help

how to controll over tabbarview controller?

iphone uiviewcontroller uitabbarcontroller uitabbar uitabbaritem

I've a problem that in my tabbarviewcontroller there are many viewcontroller in a particular tab button.I want that when I press tab button it should come first viewcontroller regarding that tab bu...

What would be the best way to persistently store HTTP responses for use in a web scraping application

python mongodb couchdb distributed-caching

I'm looking for a key/value store in python that would be suitable for holding (and caching) HTTP responses (content, HTTP headers, timestamp) keyed by request URL. The application is a web scraping