0

My web application stores files (.png, .bmp, .jpg, .jpeg, .jpe, .jfif, .gif, .tif, .tiff, .doc, .docx, .pdf, .xls, .xlsx) in the app_data/upload folder. It gets stored on live server as it is on the local system. But when trying to download, it gets downloaded with the same file size but in the corrupted format.

Here is the code that downloads the file from the live server.

string strURL = "~/App_Data/Upload/" + fileRepository.FileName;
WebClient req = new WebClient();
HttpResponse response = HttpContext.Current.Response;
response.Clear();
response.ClearContent();
response.ClearHeaders();
response.Buffer = true;
response.ContentType = "application/octet-stream";
response.AppendHeader("Content-Disposition", "attachment;filename=\"" + fileRepository.FileName + "\"");
byte[] data = req.DownloadData(Server.MapPath(strURL));
response.BinaryWrite(data);
response.TransmitFile(Server.MapPath(strURL));
FileRespository.DownloadCount(Convert.ToString(_fileID));
response.End();

Kindly find an image attached when word file is downloaded. Please help me out. Kindly find an image attached when word file is downloaded.

1 Answers1

0

Read the file as a blocks/buffers instead of transmit file.

solairaja
  • 966
  • 7
  • 17