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", "localspkgfile.zip");

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.

Answers


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

How do you use subprocess.check_output() in Python?

python python-3.x python-2.x

I have found documentation about subprocess.check_output() but I cannot find one with arguments and the documentation is not very in depth. I am using Python 3 (but am trying to run a Python 2 file

serialize each object in Object collection

c# serialization collections

I have this code for serializing my custom collection of UserData Objects. However the current property only represents the item currently being used in the collection, so it only serializes that ...