Last post Jun 28, 2009 09:49 PM by hotsheep
Jun 22, 2009 12:49 AM|hotsheep|LINK
i have this code, but it throws an exception if the image doesn't exist, is there a better way to check without using try/catch
Private Const PATH_TO_IMAGE As String = "http://test.com.au/news/testimage.jpg"
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Dim pathImage As String = PATH_TO_IMAGE
Dim myRequest As WebRequest = System.Net.WebRequest.Create(pathImage)
Dim myResponse As WebResponse = myRequest.GetResponse()
Jun 22, 2009 02:43 AM|PeteNet|LINK
you could probably use the WebClient and check on size of bytes, as discussed here:
http://forums.asp.net/t/1190512.aspx , read here too:
if you were to use the code you have you would rather use a check function like the 'DoesImageExistRemotely' shown here:
Jun 26, 2009 12:25 AM|hotsheep|LINK
Jun 26, 2009 07:49 AM|Bober Song - MSFT|LINK
Just catch whether the image is existing on the internet.
//read the image and find whether the image exists
//alert the message "the image is not existing"
I hope it is helpful to you.
Jun 28, 2009 09:49 PM|hotsheep|LINK
yeah, i've wrapped my code in a try/catch and it seems to be working fine
i just thought that there might be a way of checking if an image exists without throwing an exception for performance reasons. i was hoping that there might be a method that would return false or -1 or nothing if an image didnt exist.
there's an idea for microsoft