我正在尝试使用发送 xlsx 文件
Response.Clear();
Response.AddHeader("Content-Disposition", "attachment; filename=" + fileName);
Response.AddHeader("Content-Length", file.Length.ToString());
Response.ContentType = "application/vnd-ms.excel";
Response.TransmitFile(file.FullName);
Response.End();
弹出IE对话框,我可以成功保存文件,然后从文件夹中打开它,效果很好。但是如果我在 IE 对话框中单击“打开”,我会得到“无法下载 myFile.xlsx”。我单击“重试”,它会打开 Excel,但会弹出“Excel 无法打开文件 'myFile.xlsx',因为文件格式或文件扩展名无效......”错误。
我目前正在以调试模式从 VS2010 运行该站点。
有谁知道为什么它会让我保存,但不能直接打开?
编辑
Chrome 只是下载它。FF尝试打开它,但给出了错误The file you are trying to open, 'myFile.xlsx.xls', is in a different format than specified by the file extension...
我可以选择打开它并且它成功打开,但在只读模式下。
所以,这里正在发生一些时髦的事情。
文件名 = "我的文件.xlsx"
编辑 2
这是在 IE 9 中。我也尝试过octet-stream
并application/vnd.openxmlformats-officedocument.spreadsheetml.sheet
作为 ContentType。