I am working on a web application that includes the ability to save downloaded files. Files are stored in the SQL database in the image column and served through the GetFile.aspx page using Response.BinaryWrite ().
Until yesterday, I had problems downloading Office 2007/2010 files. The file will load without problems, but when Word (or Excel or any Office program) opens it, it will complain about the damaged file. But it will still be open without any obvious problems or missing data. The solution was to include the Content-Length header in the response:
If dr.Read() Then
Response.Clear()
Response.Buffer = True
Response.AppendHeader("Content-disposition", "attachment;filename=" + Server.UrlEncode(dr("FileName").ToString()))
Response.AppendHeader("Content-Length", dr("ContentSize").ToString())
Response.ContentType = dr("ContentType").ToString()
Response.BinaryWrite(dr("FileContent"))
End If
dr.Close()
Response.Flush()
Response.End()
dr is a SqlDataReader.
(Windows 7, IIS 7.5, ASP 2.0). . (Windows Server 2003, IIS 6) . WireShark , Content-Length ! , ( : Response.AppendHeader("TestHeader", "TestValue")), , ContentSize , , Response.AppendHeader("Content-Length", "1234567"), !
Fiddler ; dev- ( , , ... Fiddler ), !
? - IIS 6 ? , ?