我遇到了一些问题,使用C#WebClient DownloadFileAsync,并希望你能帮助我。DownloadFileAsync:多个文件
这里是我的情况:
我下载多个文件同时采用Web客户端DownloadFileAsync同一时间(http://example.com/abc/1.jpg,http://example.com/abc/efg/2.jpg等)。
我当前的示例代码:
while (theres still files in http://example.com/abc/) {
// filename will be something like /abc/1.jpg, /abc/efg/2.jpg
if (!file.exists(directory.getcurrentdirectory()+filename.Replace('/', '\\'))) {
WebClient webClient = new WebClient();
webClient.DownloadProgressChanged += new DownloadProgressChangedEventHandler(downloadProgressChanged);
webClient.DownloadFileCompleted += new AsyncCompletedEventHandler(downloadCompleted);
webClient.DownloadFileAsync(new Uri("http://example.com"+filename), Directory.GetCurrentDirectory()+filename.Replace('/', '\\'));
}
如何让这个所有的文件被下载在一个显示进度条?
例如。 1.jpg为50kb,2.jpg为50kb,1.jpg完成下载时进度条会显示50%,并且进度条中的2.jpg会从51%到100%。
另外,如果文件名是/abc/1.jpg,如果我的当前目录没有名为abc的文件夹,则下载将不起作用。如何根据文件名自动创建文件夹? (例如/random123/3.jpg,/anotherrandom/4.jpg等)
你在问两个不相关的东西,你应该问两个问题。 – svick
在开始下载之前,你知道所有图像的大小吗?还是应该进度条独立于图像的大小? – svick
在开始下载之前,我不知道所有图像的总大小。它应该是动态的。 – initialshl