从http网站下载文件失败,并显示错误“ System.IO.IOException”

时间:2019-11-20 06:48:19

标签: c# asp.net .net

从HTTP站点下载文件失败,并显示错误

  

“ System.IO.IOException:该进程无法访问文件'c:\ temp \ python-3.8.0-amd64.exe',因为它正在被另一个进程使用”。

url = "http://ip:43/installer/python-3.8.0-amd64.exe"
Uri uri = new Uri(url);
filename = uri.Segments[uri.Segments.Length - 1];
installer_path = $@"c:\Temp\{filename}";

using (var client = new WebClient())
{
   client.DownloadFile(url, installer_path);
   client.Dispose();
}

2 个答案:

答案 0 :(得分:1)

  1. 检查该位置上的文件是否可用
  2. IIS
  3. 中检查 MIME 配置
  4. 还要检查对目标的访问权限
client.DownloadFileCompleted += WcOnDownloadFileCompleted;

private static void WcOnDownloadFileCompleted(object sender, AsyncCompletedEventArgs e)
{
    if (!e.Cancelled && e.Error == null)
    {
        //async download completed successfully
    }
    handle.Set(); // in both the case let the void main() know that async event had finished so that i can quit
}

答案 1 :(得分:0)

  1. 打开任务管理器
  2. 转到“处理”标签
  3. 在列表中搜索“ python-3.8.0-amd64.exe”
  4. 如果它在那里,则右键单击它并选择“结束任务”
  5. 现在运行您的代码,应该没问题