Blogs
 
Thursday, September 29, 2005

Today I stumbled across an interesting issue that came to light only after moving a product to a production server which uses SSL (HTTPS). We had a page that exported some data as an Excel CSV file, by setting the Content-Disposition. Works great on the dev server, but on the live server, Internet Explorer was returning "File not found", with a seemingly random (incorrect) filename. At it refused to download the file.

After quite a bit of digging, and determining that it was a bug with IE... I stumbled across this page which outlined the fix.

http://www.highdots.com/forums/asp-net/content-disposition-doesnt-set-filename-674439.html

Here is the working code in VB.NET:

Context.Response.Clear() 
Response.ClearContent()
Response.ClearHeaders()
Response.Cookies.Clear()
Response.Cache.SetCacheability(HttpCacheability.Private)
Response.CacheControl = "private"
Response.Charset = System.Text.UTF8Encoding.UTF8.WebName
Response.ContentEncoding = System.Text.UTF8Encoding.UTF8
Response.AppendHeader("Content-Length", f.Length.ToString())
Response.AppendHeader("Pragma", "cache")
Response.AppendHeader("Expires", "60")
Response.ContentType = "application/vnd.ms-excel"
Response.AddHeader("Content-Disposition", "attachment;filename=" & fname)
Response.Write(filecontents) Response.End()

Dusty Davidson
Lead Software Developer



Archive

Recent Entries

Blogs we read


Page 1 Of 1 (1 items)