Tag: asp.net mvc

使用c#代码下载的zip文件无效

我有一个Dot Net MVC服务器,存储一些zip文件。 如果单击超链接,我可以成功下载这些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无法正确下载文件。 任何人都可以建议我下载文件的方法。