public static bool IsURLExist(string url) { bool valid = false; try { WebRequest req = WebRequest.Create(url); using (WebResponse res = req.GetResponse()) { } valid = true; } catch (WebException ex) { Console.Write(" =====> "); CColor.WriteLineC(" ### " + ex.Message, "red"); } return(valid); }
public static void DoAGetRequest(string link, string nFileFix) { // Construct HTTP request to get the file Console.Write("--- Dowloading: "); CColor.WriteLineC(Program.FixStringChar(link.Split('/').Last()), "yellow"); using (WebClient client = new WebClient()) { try { // Specify that the DownloadFileCallback method gets called // Specify a progress notification handler. client.DownloadProgressChanged += new DownloadProgressChangedEventHandler(DownloadProgressCallback); // when the download completes. //client.DownloadFileCompleted += new AsyncCompletedEventHandler(DownloadFileCallback); client.DownloadFileAsync(new Uri(link), nFileFix); } catch (Exception ex) { Program.pL.Percent = -1; CColor.WriteLineC(" ### Error # \r\n" + ex.Message, "red"); } } }