Content-Disposition attachment vs inline
Today I ran into an interesting issue. We have some legacy code in .NET 1.1 that exports an HTML table to Microsoft Excel. This export occurs by simply rendering the table via Response.Write and setting the header content-disposition to “attachment; filename=FileName.xls”. The original code looked something like this:
Response.Clear() Response.AddHeader("content-disposition", "attachment;filename=SalesByProductReport.xls") Response.Charset = "utf-8" Response.Cache.SetCacheability(HttpCacheability.NoCache) Response.ContentType = "application/vnd.ms-excel" Dim stringWrite As IO.StringWriter = New System.IO.StringWriter Dim htmlWrite As HtmlTextWriter = New HtmlTextWriter(stringWrite) tblTable.RenderControl(htmlWrite) Response.Write(stringWrite.ToString()) Response.Flush() Response.End()
The problem that occurred was that any user using Internet Explorer (surprise, surprise!) would get a prompt to download the file but the file would not download! The file worked properly in all other browsers. The solution is to change
Now, why exactly does this work? I’m not sure, so if you know please tell me.