繁体   English   中英

在asp.net中打开docx

[英]open docx in asp.net

我需要在浏览器中打开docx文件。 尝试使用下面的代码。 但是会发生错误,表明文件已损坏。 内容类型是否正确,也尝试使用内容类型application / msword。

Response.AddHeader(“ content-disposition”,“ inline; filename =” + DisplayFileName); Response.ContentType =“ application / vnd.openxmlformats-officedocument.wordprocessingml.document”; // getContentType(filename); Response.WriteFile(FULLPATH); 到Response.End(); Response.Flush();

如果指定了适当的内容类型,则该代码可用于所有其他文件类型。 问题仅在于docx。

您遇到什么错误?

您可以为docx尝试这种MIME类型吗?

application/vnd.ms-xpsdocument

编辑:我可以使它像这样工作:

Response.ClearContent();
Response.ClearHeaders();

Response.ContentType = "application/vnd.openxmlformats-officedocument.wordprocessingml.document";

string fileName = "C:\\Your\\File\\Name.docx"; //change to your file name and path

Response.WriteFile(fileName);
Response.End();

您是否看过压缩?

docx是zip文件,如果gzip压缩在服务器上处于活动状态,则它不会弄乱数据(可能是双重压缩,也可能是客户端假设IIS压缩了该数据,客户端尝试从docx中提取数据)

只是一个想法,我不是说那是什么,但是我在iis压缩和zip文件方面遇到了一些麻烦,因此也许与docx有关。

ps:您尝试过xslx或pptx吗?

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM