English 中文(简体)
在asp.net中打开docx
原标题:open docx in asp.net

我需要在浏览器中打开docx文件。尝试使用以下代码。但出现了文件已损坏的错误。内容类型正确吗,也用内容类型应用程序/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压缩处于活动状态,它就不能篡改数据(可能是双重压缩,也可能是客户端试图从Docx中提取数据,假设它已被IIS压缩)

这只是一个想法,我不是这么说的,但我在iis压缩和zip文件方面遇到了一些问题,所以它可能与docx有关。

ps:你试过xslx还是pptx?





相关问题
Anyone feel like passing it forward?

I m the only developer in my company, and am getting along well as an autodidact, but I know I m missing out on the education one gets from working with and having code reviewed by more senior devs. ...

How to Add script codes before the </body> tag ASP.NET

Heres the problem, In Masterpage, the google analytics code were pasted before the end of body tag. In ASPX page, I need to generate a script (google addItem tracker) using codebehind ClientScript ...

Transaction handling with TransactionScope

I am implementing Transaction using TransactionScope with the help this MSDN article http://msdn.microsoft.com/en-us/library/system.transactions.transactionscope.aspx I just want to confirm that is ...

System.Web.Mvc.Controller Initialize

i have the following base controller... public class BaseController : Controller { protected override void Initialize(System.Web.Routing.RequestContext requestContext) { if (...

Microsoft.Contracts namespace

For what it is necessary Microsoft.Contracts namespace in asp.net? I mean, in what cases I could write using Microsoft.Contracts;?

Separator line in ASP.NET

I d like to add a simple separator line in an aspx web form. Does anyone know how? It sounds easy enough, but still I can t manage to find how to do it.. 10x!

热门标签