我想“下载”一个文件(更像是将其从一个目的地复制到另一个目的地),以尝试找到执行此操作的最佳方法。我已经尝试过 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 的观点是什么?
谢谢。