【发布时间】:2012-11-14 09:39:08
【问题描述】:
我想“下载”一个文件(更像是从一个目的地复制到另一个目的地),以尝试找到执行此操作的最佳方法。我已经尝试过 xcopy 等。现在我正在尝试 WebClient。我的代码如下:
WebClient client = new WebClient();
client.DownloadProgressChanged += new DownloadProgressChangedEventHandler(client_DownloadProgressChanged);
client.DownloadFileCompleted += new AsyncCompletedEventHandler(client_DownloadFileCompleted);
foreach (string drivePath in _destRepository.Destinations)
{
do
{
AsyncItem job = _repository.GetNextAsyncItem();
string source = job.DownloadLocation;
string destination = drivePath + job.Destination;
client.DownloadFileAsync(new Uri(source), destination);
} while (_repository.QueueCount < 1);
}
AsyncItem 只是一个包含源和相对目标(没有驱动器位置的目标)的自定义类。然后将给出其驱动器路径,然后客户端显示 DownloadFileAsync。但是在 Event Completed 函数中我得到一个错误。 InnerException 告诉我目的地不存在?
当然它还不存在,WebClient 必须做到。这让我相信也许 WebClient 不会创建文件夹结构?其中一些文件位于两层深处。
StackOverflow 的意见是什么?
谢谢。
【问题讨论】:
标签: c# .net visual-studio-2010 webclient