When downloading a .xlsx file, the downloaded file always prompts an error.
Error message:
Excelfound unreadable content in Chapter 12.xlsx. Restore the workbook content? If you trust the source of this workbook, click "yes ".
Click "yes": Excel has completed file-level verification and repair. Some parts of this workbook may have been repaired or discarded.
Download after solutionCodeAs follows:
Filestream = New Filestream (pfilename, filemode. open)
Long Filesize = Filestream. length;
Context. response. contenttype = " Application/octet-stream " ;
Context. response. addheader ( " Content-Disposition " , " Attachment; filename = \" " + Filename + " \"; " );
Context. response. addheader ( " Content-Length " , Filesize. tostring ());
Byte [] Filebuffer = New Byte [Filesize];
Filestream. Read (filebuffer, 0 ,( Int ) Filesize );
Context. response. binarywrite (filebuffer );
Context. response. End ();
After this line of code is added, the problem is solved.
Context. response. addheader ("Content-Length", filesize. tostring ());
Refer:
Http://www.cnblogs.com/ami/archive/2006/07/20/455760.html