downloaded zip file using c# code is invalid

I have a Dot Net MVC server that stores some zip files. I'm able to download these zip files successfully if I click on the hyperlink. However if I try to download the zip file using WebClient's DownloadFile, I'm able to download the zip file I get an error "Windows cannot open the folder, compressed zip folder is invalid"

Server side code :

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);

Client side I'm using Webclient to download this file

WebClient wc = new WebClient();
wc.DownloadFile("http://servername/Results/DownloadFile/853", "");

If I download file by clicking hyperlink on browser, the filesize is 2.9 mb. However using webclient the file size is 5kb. Looks like WebClient is not able to download the file properly. Can anyone please suggest me a way to download the file.


I don't know what is wrong with your code, but that 5kb file you are downloading is almost certainly an HTML error page, which might contain information, such as a stacktrace, that will help you figure out what is going wrong. Change its extension to .html and open it in your browser.

Need Your Help

Virtual machine supporting multiple displays

hardware virtual monitor environment

Is there a way to get MS virtual PC 2007 to support multiple displays? Or is there another virtual machine product available that will allow me to work with multiple displays?

capistrano deploy_via :copy using git tags?

ruby git capistrano

I'm new to capistrano and I'm trying to figure out if it's possible to deploy to multiple servers by using a push method with git tags as a reference. It's a little more complicated than that, as t...