Sometime you require to display remote images in the Web Pages, like Ads, Banner etc, it may be from different domain or a different application. This code will help you to check the existence of a Remote file
using System.Net;
/// <summary> /// Checks the file exists or not. /// </summary> /// <param name="url">The URL of the remote file.</param> /// <returns>True : If the file exits, False if file not exists</returns> private bool RemoteFileExists(string url) { try { //Creating the HttpWebRequest HttpWebRequest request = WebRequest.Create(url) as HttpWebRequest; //Setting the Request method HEAD, you can also use GET too. request.Method = "HEAD"; //Getting the Web Response. HttpWebResponse response = request.GetResponse() as HttpWebResponse; //Returns TURE if the Status code == 200 return (response.StatusCode == HttpStatusCode.OK); } catch { //Any exception will returns false. return false; } }
|
No responses found. Be the first to respond and make money from revenue sharing program.
|