【发布时间】:2012-09-03 06:59:18
【问题描述】:
我有一个存储一些 zip 文件的 Dot Net MVC 服务器。如果单击超链接,我可以成功下载这些 zip 文件。但是,如果我尝试使用 WebClient 的 DownloadFile 下载 zip 文件,我可以下载 zip 文件我收到错误“Windows 无法打开文件夹,压缩的 zip 文件夹无效”
服务器端代码:
public FilePathResult DownloadFile(int id)
{
string resultsdir = AppDomain.CurrentDomain.BaseDirectory + "Data\\ResultsDir\\" + res.RequestId.ToString();
string downloadFile = System.IO.Path.GetFileName(res.DownloadPath);
string zipPath = System.IO.Path.Combine(resultsdir, downloadFile);
return File(zipPath, "application/zip", downloadFile);
}
客户端我使用Webclient来下载这个文件
WebClient wc = new WebClient();
wc.DownloadFile("http://servername/Results/DownloadFile/853", "localspkgfile.zip");
如果我通过单击浏览器上的超链接下载文件,文件大小为 2.9 mb。但是使用 webclient 文件大小为 5kb。看起来 WebClient 无法正确下载文件。谁能给我一个下载文件的方法。
【问题讨论】:
标签: c# c asp.net-mvc webclient-download