How to use the ResourceDownloaded class to download files using httpclient?
The problem is in this line I'm not sure what should I give it. I have in the designer of form1 a progressBar.
await ResourceDownloader.DownloadWithProgress.ExecuteAsync(client, list[i], textBoxRadarPath.Text, , () =>
what should I put for the downloadprogresshandler ? and then after it for the next parameter?
I want to use the httpclient with the ResourceDownloaded class to download images with a progressbar and to report to label/s information's like download speed and amount left to download for each file.
usage in form1:
using Ookii.Dialogs.WinForms;
using System.Text;
namespace Downloading_Files
{
public partial class Form1 : Form
{
List<string> list = new List<string>();
public Form1()
{
InitializeComponent();
textBoxRadarPath.Text = Properties.Settings.Default.RadarFolder;
}
internal List<string> Sites()
{
Radar radar = new Radar(textBoxRadarPath.Text);
radar.PrepareLinks();
foreach (var link in radar.links)
{
list.Add(link);
}
// [...] add more URLs
return list;
}
private void Form1_Load(object sender, EventArgs e)
{
}
int counter = 0;
private async void btnStartDownload_Click(object sender, EventArgs e)
{
HttpClient client = new HttpClient();
for (int i = 0; i < list.Count; i++)
{
await ResourceDownloader.DownloadWithProgress.ExecuteAsync(client, list[i], textBoxRadarPath.Text, , () =>
{
var requestMessage = new HttpRequestMessage(HttpMethod.Get, list[i]);
requestMessage.Headers.Accept.TryParseAdd("application/octet-stream");
return requestMessage;
});
}
}
private void btnCancelDownload_Click(object sender, EventArgs e)
{
}
private void btnDownloadFolder_Click(object sender, EventArgs e)
{
RadarFolderDialog();
}
private void RadarFolderDialog()
{
VistaFolderBrowserDialog dlg = new VistaFolderBrowserDialog();
dlg.ShowNewFolderButton = true;
if (dlg.ShowDialog() == DialogResult.OK)
{
if (!dlg.SelectedPath.EndsWith("Radar"))
{
if (!Directory.Exists(dlg.SelectedPath))
{
Directory.CreateDirectory(dlg.SelectedPath + "\\Radar");
}
Properties.Settings.Default.RadarFolder = dlg.SelectedPath;// + "\\Radar";
textBoxRadarPath.Text = dlg.SelectedPath;// + "\\Radar";
Properties.Settings.Default.Save();
}
else
{
Properties.Settings.Default.RadarFolder = dlg.SelectedPath;
textBoxRadarPath.Text = dlg.SelectedPath;
Properties.Settings.Default.Save();
}
}
}
}
}
I have this class and I want to use it in form1 to download files.
In this link for some reason, I can't add the code in here:
I saw the answer here in this link and this is what I want to do but I'm not sure how to use it in form1.