How to check if an image exists http: //someurl/myimage.jpg in C # / ASP.NET There seems to be a way to check this, but I cannot find it.
I found this one , but actually it does not answer the question.
This code should work:
private static bool UrlExists(string url) { try { 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; else throw; } }
You can try to use System.Net.WebRequestit to send a “HEAD” request to this URL and check the response to see if it exists - this should be done without preloading.
System.Net.WebRequest
string fileextension = Path.GetExtension( );
if (fileextension.ToLower() == ".png" || fileextension.ToLower() == ".jpg" || fileextension.ToLower() == ".jpeg" || fileextension.ToLower() == ".gif" || fileextension.ToLower() == ".bmp"){}
, this this . , , FileExist.
System.Net.WebClient.DownloadFile, URL- , . ( , 404 )
Its the only way to do this from a URL. The System.IO namespace and all the functions there are designed for files on the local machine or on the network, so in this situation they will be useless to you.
Source: https://habr.com/ru/post/1721336/More articles:json data transfer at startup - javascriptПредотвратить проверку/подтверждение события при запуске в пользовательском текстовом поле - vb.net - eventsProcessing large images with Delphi to save as .jpeg - image-processingCan I access WMI through ADO? - adoКак настроить Django Flatpage для отображения нового поля на странице списка изменений администратора? - djangohttps://translate.googleusercontent.com/translate_c?depth=1&pto=aue&rurl=translate.google.com&sl=ru&sp=nmt4&tl=en&u=https://fooobar.com/questions/1721337/repository-pattern-with-a-legacy-database-and-linq-to-sql&usg=ALkJrhhaYSTm4Zt7qAhoKM_bP-YbERcBuQWPF - DataTemplate without a container, elements as rows in a grid? - .netUnderstanding factorial function in python - pythonC # or Python for my application - pythonShould I use comments in code, liberally? - coding-styleAll Articles