C# file export issue

半城伤御伤魂 提交于 2019-12-10 16:48:37

问题


I use this code to export/open files (pdf/xls/doc).

Response.Clear();
Response.Buffer = true;

Response.ContentEncoding = System.Text.Encoding.UTF8;
Response.Charset = "UTF-8";
Response.ContentType = mimeType;

Response.AppendHeader("content-disposition", "inline; filename=" + fileName + "." + extension);

Response.BinaryWrite(bytes);
Response.End();

When I open a doc file with Word and click export to xls or pdf, nothing happens until I close Word. After I close Word I am already able to open xls and pdf too.

This problem exists when I open xls with Excel.

What is the reason?


回答1:


Depending on the word version you use, I would say that the problem comes from the inline content-disposition

In recent versions of Word ( seen in Word 2010 ), it tries to open the document in WEBDAV mode when inline, which might cause issues (locks, missing cookies or credential when trying to export/print the document)

You may look at your network traffic to see if this WEBDAV behavior is involved, and see if content-disposition attachment solves the problem.

Hope this will help




回答2:


The reason is because Word, and other Word-like programs lock the open files to avoid double open again. So the locked file can not be opened again from your application.



来源:https://stackoverflow.com/questions/15703539/c-sharp-file-export-issue

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!