我使用此代码导出/打开文件(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();
当我用Word打开doc文件并单击导出到xls或pdf时,在关闭Word之前没有任何反应。 在我关闭Word后,我已经能够打开xls和pdf了。
使用Excel打开xls时存在此问题。
是什么原因?
答案 0 :(得分:2)
原因是因为Word和其他类似Word的程序会锁定打开的文件以避免再次打开。因此无法再从您的应用程序中再次打开锁定的文件。
答案 1 :(得分:1)
根据您使用的单词版本,我会说问题来自inline
content-disposition
在Word的最新版本(在Word 2010中看到)中,它会尝试在WEBDAV
时以inline
模式打开文档,这可能会导致问题(锁定,缺少Cookie或凭据导致尝试导出时/打印文件)
您可以查看网络流量,看看是否涉及此WEBDAV行为,并查看content-disposition
attachment
是否解决了问题。
希望这会有所帮助