How to download files using webclient downloadfileasync ?

  • Thread starter Thread starter Chocolade1972
  • Start date Start date
C

Chocolade1972

Guest
private void downloadsources()
{
string link = "Ree MyWeb";



for (int i = 2; i < 141; i++)
{

sourcers.Add(link + "index" + i + ".html");
}

WebClient wc = new WebClient();
wc.Headers.Add("User-Agent: Other");
wc.DownloadFileCompleted += Wc_DownloadFileCompleted;
wc.DownloadFileAsync(new Uri(sourcers[0]), @"e:\dr\htmlsources\source" + sourcers[0] + ".html");

wc.Dispose();
}

private void Wc_DownloadFileCompleted(object sender, AsyncCompletedEventArgs e)
{
WebClient wc = new WebClient();

sourcers.RemoveAt(0);

if(sourcers.Count > 0)
{
wc.DownloadFileAsync(new Uri(sourcers[0]), @"e:\dr\htmlsources\source" + sourcers[0] + ".html");
}

wc.Dispose();
}

First I'm building the sources links. Then downloading. It's downloading the first source but then never continue.

It's getting to the Wc_DownloadFileCompleted to line :

wc.DownloadFileAsync(new Uri(sourcers[0]), @"e:\dr\htmlsources\source" + sourcers[0] + ".html");

But then never continue.

I want to download all the sourcers(Should be sources but never mind now).

Continue reading...
 
Back
Top