文件从app_data文件夹下载,但格式已损坏

时间:2014-02-27 05:50:22

标签: c#-4.0 download asp.net-4.0 app-data

我的网络应用程序存储文件(.png,.bmp,.jpg,.jpeg,.jpe,.jfif,.gif,.tif,.tiff,.doc,.docx,.pdf,.xls,.xlsx )在app_data / upload文件夹中。它存储在本地系统上的实时服务器上。但是在尝试下载时,它会以相同的文件大小下载,但格式已损坏。

以下是从实时服务器下载文件的代码。

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

请在下载word文件时找到附加的图像。 请帮帮我。 Kindly find an image attached when word file is downloaded.

1 个答案:

答案 0 :(得分:0)

将文件作为块/缓冲区而不是传输文件读取。