在asp.net中打开docx [英] open docx in asp.net

查看:41
本文介绍了在asp.net中打开docx的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I have a requirement of opening the docx file in the browser. Tried with the code below. But error occurs that the file is corrupt. Is the content type correct, tried with thecontent type application/msword also.

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.

The code works for all other file types when the appropriate content type is given. The problem is only with docx.

推荐答案

您遇到什么错误?

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

Can you try this MIME type for docx?

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();

这篇关于在asp.net中打开docx的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆