How can I solve the problem of downloading the .xlsx file?

Source: Internet
Author: User
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

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.