Refer to Meng xianhui's answer at the Microsoft Forum (http://social.microsoft.com/Forums/zh-CN/1761/thread/61df2773-c8ad-416e-9797-f28201145f8d)
The key is to specify the encoding method for the file name to solve this problem.
In addition, if the file name and suffix are not specified in content-disposition, the output format is automatically changed to. Zip.
The relevant information is explained as follows :(Http://blog.minidx.com/2008/01/24/436.html)
Previous office documents were in the binary format of 100%. Third-party tools are very inconvenient to operate, while office2007 is based on XML format as a whole. This does not mean that office2007 documents can be saved in XML format. The default document format of office2007 is XML (Word docx and Excel XLSX ). Some may be surprised that after opening docx in a text editor, the binary format is still displayed, and it is not XML. In fact, docx is not a common XML format. Of course, it is not just an XML file. docx is essentially a zip file with a series of XML, directories, and other files. If we change docx to zip. You can use software such as WinZip to unbind it.
String vfullname = gazoudt [0]. filepath;
String vextendname = "";
String voutputname = gazoudt [0]. reference;
Switch (Int. parse (type ))
{
Case excle:
Case excle_2007:
If (vfullname. endswith ("XLSX "))
{
Vextendname = voutputname. endswith (". XLSX ")? "": ". XLSX ";
Response. contenttype = "application/vnd. openxmlformats-officedocument.spreadsheetml.sheet ";
}
Else
{
Vextendname = voutputname. endswith (". xls ")? "": ". Xls ";
Response. contenttype = "application/vnd. MS-excel ";
}
Response. appendheader ("content-disposition", String. format ("attachment; filename = {0} {1}", httputility. urlencode (voutputname, system. text. utf8encoding. utf8), vextendname ));
Break;
Case PDF:
Response. contenttype = "application/pdf ";
Response. appendheader ("content-disposition", "attachment ");
Break;
Case word:
Case word_2007:
If (vfullname. endswith ("docx "))
{
Vextendname = voutputname. endswith (". docx ")? "": ". Docx ";
Response. contenttype = "application/vnd.openxmlformats-officedocument.wordprocessingml.doc ument ";
}
Else
{
Vextendname = voutputname. endswith (". Doc ")? "": ". Doc ";
Response. contenttype = "application/MSWord ";
}
Response. appendheader ("content-disposition", String. format ("attachment; filename = {0} {1}", httputility. urlencode (voutputname, system. text. utf8encoding. utf8), vextendname ));
Break;
}
Response. charset = "UTF-8 ";
Response. transmitfile (gazoudt [0]. filepath );
Response. End ();