开发者

open docx in asp.net

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.Flus开发者_运维百科h();

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


What error did you get?

Can you try this MIME type for docx?

application/vnd.ms-xpsdocument

EDIT: I can get it working like this:

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


Have you looked about compression ?

Docx are zip file, if the gzip compression is active on the server it can't mess around the data (maybe double compression or maybe the client tries to extract the data from the docx assuming it's been compressed by IIS)

It's just an idea i'm not saying it's that , but I had some trouble with iis compression and zip files so maybe it's relevant with docx.

ps : have you tried xslx or pptx ?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜