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

Executing a controller action when a button is clicked on the client

c# ajax asp.net-mvc razor html-helper

Are we supposed to be able to follow a AJAX call in the debugger to see what's going on? Because for some reason it seems like the call isn't going to where it's supposed to go to.

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.