C # file export problem

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 document file using Word and select export for xls or pdf, nothing happens until I close Word. After closing Word, I can already open xls and pdf.

This problem exists when I open xls using Excel.

What is the reason?

+4
source share
2 answers

Depending on the version of the word used, I would say that the problem arises from inline content-disposition

In recent versions of Word (seen in Word 2010), it tries to open a document in WEBDAV mode when inline , which can cause problems (locks, missing cookies or credentials when trying to export / print a document)

You can look at your network traffic to see if this is the behavior of WEBDAV and see if the content-disposition attachment resolves the issue.

Hope this helps

+1
source

The reason is that Word and other Word-like programs block open files to avoid double opening. Thus, a locked file cannot be reopened from your application.

+2
source

All Articles