/// <summary> /// 检查文件信息。 /// </summary> private void btnCheck_Click(object sender, EventArgs e) { // 初始化 MultiThreadedWebDownloader。 downloader = new MultiThreadedWebDownloader(tbURL.Text); downloader.Proxy = this.proxy; try { downloader.CheckFile(); //更新UI界面。 tbURL.Enabled = false; btnCheck.Enabled = false; tbPath.Enabled = true; btnDownload.Enabled = true; } catch { // 如果有任何的异常,像System.Net.WebException 或者 // System.Net.ProtocolViolationException, 就说明读取文件信息时有错误, //并且该文件是不能被下载的。 MessageBox.Show("获取文件信息有错误." + " 请确保URL是有效的!"); } }
/// <summary> /// Check the file information. /// </summary> private void btnCheck_Click(object sender, EventArgs e) { // Initialize an instance of MultiThreadedWebDownloader. downloader = new MultiThreadedWebDownloader(tbURL.Text); downloader.Proxy = this.proxy; // Register the events of HttpDownloadClient. downloader.DownloadCompleted += DownloadCompleted; downloader.DownloadProgressChanged += DownloadProgressChanged; downloader.StatusChanged += StatusChanged; try { string filename = string.Empty; downloader.CheckUrl(out filename); if (string.IsNullOrEmpty(filename)) { this.DownloadPath = string.Format("{0}\\{1}", Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments), downloader.Url.Segments.Last()); } else { this.DownloadPath = string.Format("{0}\\{1}", Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments), filename); } // Update the UI. tbURL.Enabled = false; btnCheck.Enabled = false; tbPath.Enabled = true; btnDownload.Enabled = true; } catch { // If there is any exception, like System.Net.WebException or // System.Net.ProtocolViolationException, it means that there may be an // error while reading the information of the file and it cannot be // downloaded. MessageBox.Show("There is an error while get the information of the file." + " Please make sure the url is accessible."); } }