Good afternoon, help me figure out how to properly make the download files on the collection of links. There is such a list here:
public List <string> MusicFilesList() { var links = new List<string>(); links.Add("http://mysite.com/music.mp3"); links.Add("http://mysite.com/music.mp3"); links.Add("http://mysite.com/music.mp3"); links.Add("http://mysite.com/music.mp3"); links.Add("http://mysite.com/music.mp3"); links.Add("http://mysite.com/music.mp3"); return links; } On the form there is a progress bar and a button that starts loading.
private void downloadMusic_Click(object sender, EventArgs e) { foreach(var link in MusicFilesList()) { Downloader(link, ); } } And the method that downloads
private void Downloader(string link, string filepath) { using (WebClient wc = new WebClient()) { wc.DownloadProgressChanged += Wc_DownloadProgressChanged; wc.DownloadFileCompleted += Wc_DownloadFileCompleted; wc.DownloadFileAsync(new Uri(link), filepath); } } How can I tell where to download? If one file is downloaded, then I use SaveFileDialog. And for a large number of files I can not do that I would just point to the folder where he himself downloaded.
Update. This is how I download a single file.
private void downloadPhoto_Click(object sender, EventArgs e) { using (var dialog = new SaveFileDialog()) { dialog.Filter = "MusicFile|*.mp3"; dialog.Title = "Сохранить как"; dialog.FileName = fileName; var result = dialog.ShowDialog(); if(result == DialogResult.OK) { Downloader(musicLink, dialog.FileName); } } } With Folder, this is what I built, but it only downloads one file.
private void downloadAlbum_Click(object sender, EventArgs e) { using (var dialog = new FolderBrowserDialog()) { if (dialog.ShowDialog() == DialogResult.OK) { foreach (var link in MusicFilesList()) { fileName = $"{musiclist.SelectedItem.ToString().Split('/')[6]}"; using (var wc = new WebClient()) { wc.DownloadFile(link.ToString(), dialog.SelectedPath + "/" + fileName); } } } } }
FolderBrowserDialog- tym32167