private void DownloadStart(object st) { int selectedIndex = lwDownloadInfo.SelectedIndices[0]; try { // Check whether the file exists. if (File.Exists(tbPath[selectedIndex].Trim())) { string message = "There is already a file with the same name, " + "do you want to delete it? " + "If not, please change the local path. "; var result = MessageBox.Show( message, "File name conflict: " + tbPath[selectedIndex].Trim(), MessageBoxButtons.OKCancel); if (result == System.Windows.Forms.DialogResult.OK) { File.Delete(tbPath[selectedIndex].Trim()); } else { return; } } // Construct the temporary file path. string tempPath = tbPath[selectedIndex].Trim() + ".tmp"; // Delete the temporary file if it already exists. if (File.Exists(tempPath)) { File.Delete(tempPath); } // Initialize an instance of HttpDownloadClient. // Store the file to a temporary file first. int index = lwDownloadInfo.Items.Count - 1; tsslIndex.Text = String.Format("Index:{0}", index); //clients.Add(new HttpDownloadClient(selectedIndex, tbURL[selectedIndex], tempPath, selectedIndex)); clients[selectedIndex] = new HttpDownloadClient(selectedIndex, tbURL[selectedIndex], tempPath, selectedIndex); //// Register the events of HttpDownloadClient. clients[selectedIndex].DownloadCompleted += new EventHandler <HttpDownloadCompletedEventArgs>( DownloadCompleted); clients[selectedIndex].DownloadProgressChanged += new EventHandler <HttpDownloadProgressChangedEventArgs>(DownloadProgressChanged); clients[selectedIndex].StatusChanged += new EventHandler <StatusChangedArgs>(StatusChanged); // Start to download file. clients[selectedIndex].Start(); } catch (Exception ex) { MessageBox.Show(ex.Message); } }
private void DownloadStart(object st) { int selectedIndex = lwDownloadInfo.SelectedIndices[0]; try { // Check whether the file exists. if (File.Exists(tbPath[selectedIndex].Trim())) { string message = "There is already a file with the same name, " + "do you want to delete it? " + "If not, please change the local path. "; var result = MessageBox.Show( message, "File name conflict: " + tbPath[selectedIndex].Trim(), MessageBoxButtons.OKCancel); if (result == System.Windows.Forms.DialogResult.OK) { File.Delete(tbPath[selectedIndex].Trim()); } else { return; } } // Construct the temporary file path. string tempPath = tbPath[selectedIndex].Trim() + ".tmp"; // Delete the temporary file if it already exists. if (File.Exists(tempPath)) { File.Delete(tempPath); } // Initialize an instance of HttpDownloadClient. // Store the file to a temporary file first. int index = lwDownloadInfo.Items.Count - 1; tsslIndex.Text = String.Format("Index:{0}", index); //clients.Add(new HttpDownloadClient(selectedIndex, tbURL[selectedIndex], tempPath, selectedIndex)); clients[selectedIndex] = new HttpDownloadClient(selectedIndex, tbURL[selectedIndex], tempPath, selectedIndex); //// Register the events of HttpDownloadClient. clients[selectedIndex].DownloadCompleted += new EventHandler<HttpDownloadCompletedEventArgs>( DownloadCompleted); clients[selectedIndex].DownloadProgressChanged += new EventHandler<HttpDownloadProgressChangedEventArgs>(DownloadProgressChanged); clients[selectedIndex].StatusChanged += new EventHandler<StatusChangedArgs>(StatusChanged); // Start to download file. clients[selectedIndex].Start(); } catch (Exception ex) { MessageBox.Show(ex.Message); } }