How to Check Image is Exist or not on Server

To check from Image path that it is exist or not on server –

if (UrlExists(ImageURL))
Image1.ImageUrl = ImageURL;
Image1.ImageUrl = NoImageURL;

private static bool UrlExists(string url)
new System.Net.WebClient().DownloadData(url);
return true;
catch (System.Net.WebException e)
//if (((System.Net.HttpWebResponse)e.Response).StatusCode == System.Net.HttpStatusCode.NotFound)
return false;


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s