Note that there are some explanatory texts on larger screens.

plurals
  1. POAsp.Net download file error when choosing 'Open' in IE9
    text
    copied!<p>I am using Response to have my application open up a Word Document for the user. If the user chooses to save the file, it saves it and the file looks how it should when you open it. If the user chooses to open the file right away, they receive an error saying that IE couldn't open the file. If they choose 'Retry', MS Word shows an error saying it cannot find the file. Below are screen shots showing my situation. Also, here is the code I have to display the file:</p> <pre><code> this.Context.Response.Clear(); this.Context.Response.ClearContent(); this.Context.Response.ClearHeaders(); this.Context.Response.BufferOutput = true; this.Context.Response.ContentType = "application/msword"; this.Context.Response.AppendHeader("Content-Length", bytes.Length.ToString()); this.Context.Response.AddHeader("Content-Disposition", "attachment; filename=" + "Test Document.doc"); this.Context.Response.BinaryWrite(bytes); this.Context.ApplicationInstance.CompleteRequest(); </code></pre> <p>Here is the screen when prompting the user of the download: <img src="https://i.stack.imgur.com/j56Xv.jpg" alt="enter image description here"></p> <p>Here is the screen after user chooses 'Open' <img src="https://i.stack.imgur.com/0niz5.jpg" alt="enter image description here"></p> <p>Here is the screen after user chooses 'Retry'. This screen is coming for MS Word. <img src="https://i.stack.imgur.com/hSfku.jpg" alt="enter image description here"></p> <p>****EDIT**** I have found a bit of code online that I tried testing and issue still occures when I call this function:</p> <pre><code> protected void GenerateMsWordDoc() { string strBody = "&lt;html&gt;" + "&lt;body&gt;" + "&lt;div&gt;Your name is: &lt;b&gt;Billy Bob&lt;/b&gt;&lt;/div&gt;" + "&lt;table width='100%' style='background-color:#cfcfcf;'&gt;&lt;tr&gt;&lt;td&gt;1st Cell body data&lt;/td&gt;&lt;td&gt;2nd cell body data&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;" + "Ms Word document generated successfully." + "&lt;/body&gt;" + "&lt;/html&gt;"; string fileName = "MsWordSample.doc"; // You can add whatever you want to add as the HTML and it will be generated as Ms Word docs Response.AppendHeader("Content-Type", "application/msword"); Response.AppendHeader ("Content-disposition", "attachment; filename="+ fileName); Response.Write(strBody); } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload