Wednesday, 1 May 2013

http - How to check if a file exists on a server using VB.net

 Dim _Result As String
 Dim url
 url = dt.Rows(i)("ImageUrl").ToString()

 Dim myRequest As System.Net.HttpWebRequest = System.Net.WebRequest.Create(url)
 Dim myResponse As HttpWebResponse

   Try
    myResponse = myRequest.GetResponse()
 '_Result = myResponse.StatusCode.ToString();
    _Result = "1"
   Catch ex As System.Exception
    _Result = "0" 
   Finally
    myResponse.Close()
    myRequest = Nothing
    myResponse = Nothing
    GC.Collect()
   End Try
   Response.write(_Result)