Of course, you can simply check if the URL ends with a known image file extension. However, a safer method is to actually download the resource and check if the content you receive is really an image:
public static bool IsUrlImage(string url) { try { var request = WebRequest.Create(url); request.Timeout = 5000; using (var response = request.GetResponse()) { using (var responseStream = response.GetResponseStream()) { if (!response.ContentType.Contains("text/html")) { using (var br = new BinaryReader(responseStream)) {
source share