private void addBtn_Click(object sender, EventArgs e) { string uriName = urlInput.Text; Uri uriResult; bool result = Uri.TryCreate(uriName, UriKind.Absolute, out uriResult) && uriResult.Scheme == Uri.UriSchemeHttp; if (result) { if(!Directory.Exists(downloadDirectory)) { Directory.CreateDirectory(downloadDirectory); } string outfileName = GetAvailableOutputName(downloadDirectory + Path.DirectorySeparatorChar + Path.GetFileName(uriResult.LocalPath)); Console.WriteLine("outfile " + outfileName); DownloadTask downloadTask = new DownloadTask(uriName, outfileName); downloadTasks.Add(downloadTask); DownloadListItem downloadListItem = new DownloadListItem(downloadTask); downloadListItem.Text = Path.GetFileName(outfileName); downloadListItem.DownloadItemRemoved += downloadListItem_DownloadItemRemoved; flowLayoutPanel1.Controls.Add(downloadListItem); downloadTask.StartDownload(); } else { MessageBox.Show("Invalid Url"); } urlInput.Text = ""; }
private void addBtn_Click(object sender, EventArgs e) { string uriName = urlInput.Text; Uri uriResult; bool result = Uri.TryCreate(uriName, UriKind.Absolute, out uriResult) && uriResult.Scheme == Uri.UriSchemeHttp; if (result) { if (!Directory.Exists(downloadDirectory)) { Directory.CreateDirectory(downloadDirectory); } string outfileName = GetAvailableOutputName(downloadDirectory + Path.DirectorySeparatorChar + Path.GetFileName(uriResult.LocalPath)); Console.WriteLine("outfile " + outfileName); DownloadTask downloadTask = new DownloadTask(uriName, outfileName); downloadTasks.Add(downloadTask); DownloadListItem downloadListItem = new DownloadListItem(downloadTask); downloadListItem.Text = Path.GetFileName(outfileName); downloadListItem.DownloadItemRemoved += downloadListItem_DownloadItemRemoved; flowLayoutPanel1.Controls.Add(downloadListItem); downloadTask.StartDownload(); } else { MessageBox.Show("Invalid Url"); } urlInput.Text = ""; }
private void cancelBtn_Click(object sender, EventArgs e) { downloadTask.StopDownload(); if (MessageBox.Show("Do you want cancel the Download?", "", MessageBoxButtons.YesNo) == DialogResult.Yes) { downloadTask.CleanUp(); FireItemRemovedEvent(); } else { downloadTask.StartDownload(); } }