ctudorprice
asked on
Downloading a Zip file to IE using conent-disposition
I am trying to serve zip files to people so that they are given the Open, Save, Cancel dialog. I have got this code to work with Firefox, but IE somehow corrupts the file and it is unreadable on the client - though the same size as created on the server. Here is the code:
dim filename as string ="123456789.zip"
Response.Clear()
Response.ClearContent()
Response.ClearHeaders() ' just wanted to be absolutely sure that the page had not set anything and that there is no content from the page
Response.ExpiresAbsolute = Nothing
Response.CacheControl = ""
Response.AppendHeader("con tent-dispo sition", "attachment; filename=""" & filename & """")
Dim g As Integer = fi.LengthResponse.ContentT ype = "application/zip" 'tried application/x-zip-compress ed too but makes no difference
'Dim fi As New FileInfo(filename)
'Response.AppendHeader("Co ntent-Leng th", g.ToString) 'adding this made no difference
Response.WriteFile(server. mappath("/ myzipdir/" & filename)
Response.Flush()
Response.End()
The headers that IE receives:
HTTP/1.1 200 OK
Transfer-Encoding: chunked
Date: Wed, 31 May 2006 09:18:32 GMT
Content-Type: application/zip
Expires: Wed, 31 May 2006 09:18:32 GMT
Cache-Control: no-cache
Pragma: no-cache
Server: Microsoft-IIS/6.0
X-AspNet-Version: 2.0.50727
content-disposition: attachment; filename="123456789.zip"
Content-Encoding: gzip
Vary: Accept-Encoding
Via: 1.1 cbs-cache1 (NetCache NetApp/5.6.2R1)
Any ideas?
Thanks
dim filename as string ="123456789.zip"
Response.Clear()
Response.ClearContent()
Response.ClearHeaders() ' just wanted to be absolutely sure that the page had not set anything and that there is no content from the page
Response.ExpiresAbsolute = Nothing
Response.CacheControl = ""
Response.AppendHeader("con
Dim g As Integer = fi.LengthResponse.ContentT
'Dim fi As New FileInfo(filename)
'Response.AppendHeader("Co
Response.WriteFile(server.
Response.Flush()
Response.End()
The headers that IE receives:
HTTP/1.1 200 OK
Transfer-Encoding: chunked
Date: Wed, 31 May 2006 09:18:32 GMT
Content-Type: application/zip
Expires: Wed, 31 May 2006 09:18:32 GMT
Cache-Control: no-cache
Pragma: no-cache
Server: Microsoft-IIS/6.0
X-AspNet-Version: 2.0.50727
content-disposition: attachment; filename="123456789.zip"
Content-Encoding: gzip
Vary: Accept-Encoding
Via: 1.1 cbs-cache1 (NetCache NetApp/5.6.2R1)
Any ideas?
Thanks
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
GOT IT - 10 hours later.... Thanks Vinu for you answer - I guess that would have worked too but had solved it before I saw your answer. You get the points.
IE 6 is finally behaving here is the header:
HTTP/1.1 200 OK
Date: Wed, 31 May 2006 12:04:10 GMT
Content-Length: 19557
Content-Type: application/octet-stream
Expires: Thu, 01 Jun 2006 12:04:10 GMT
Cache-Control: private
Server: Microsoft-IIS/6.0
X-AspNet-Version: 2.0.50727
content-disposition: attachment; filename=2006_05_31_1319-p roperties. zip
Via: 1.1 cbs-cache1 (NetCache NetApp/5.6.2R1)
Here is the asp.net code I used:
Response.Clear()
Response.ContentType = "application/octet-stream" 'dunno why but application/zip application/x-zip-compress ed don't work
Response.ExpiresAbsolute = DateTime.Now.AddDays(1) 'make sure this is set or users won't be able to "open" the file, but will still be able to save
Dim file As System.IO.FileInfo = New System.IO.FileInfo(tempfil efullname)
Response.AddHeader("Conten t-Length", file.Length.ToString()) ' this overrides the "Transfer-Encoding: chunked" which splits the file up and causes ie problems
Response.AppendHeader("con tent-dispo sition", "attachment; filename=" & tempfilename)
Response.WriteFile(tempfil efullname)
Response.Flush()
Response.End()
IE 6 is finally behaving here is the header:
HTTP/1.1 200 OK
Date: Wed, 31 May 2006 12:04:10 GMT
Content-Length: 19557
Content-Type: application/octet-stream
Expires: Thu, 01 Jun 2006 12:04:10 GMT
Cache-Control: private
Server: Microsoft-IIS/6.0
X-AspNet-Version: 2.0.50727
content-disposition: attachment; filename=2006_05_31_1319-p
Via: 1.1 cbs-cache1 (NetCache NetApp/5.6.2R1)
Here is the asp.net code I used:
Response.Clear()
Response.ContentType = "application/octet-stream"
Response.ExpiresAbsolute = DateTime.Now.AddDays(1) 'make sure this is set or users won't be able to "open" the file, but will still be able to save
Dim file As System.IO.FileInfo = New System.IO.FileInfo(tempfil
Response.AddHeader("Conten
Response.AppendHeader("con
Response.WriteFile(tempfil
Response.Flush()
Response.End()
Hai,
That's good effort from u.. thanks for sharing the information.. really useful..
regards
Vinodh
That's good effort from u.. thanks for sharing the information.. really useful..
regards
Vinodh
ASKER
It appears that either gzip or Trasfer-Encoding: chunked is causing IE to corrupt the zip file.... Hmmmm.
I have httpZIP on my production server, so I have turned off gzip for this specific page, but I can't seem to stop the Transfer-Encoding: chunked and get a Content-Length header instead.
This is the header the browswer gets now and still not working. Anyone know how to control Transfer-Encoding in ASP.NET / IIS?
HTTP/1.1 100 Continue
Date: Wed, 31 May 2006 10:54:55 GMT
Via: 1.1 cbs-cache1 (NetCache NetApp/5.6.2R1)
HTTP/1.1 200 OK
Transfer-Encoding: chunked
Date: Wed, 31 May 2006 10:55:03 GMT
Content-Type: application/zip
Expires: Wed, 31 May 2006 10:55:03 GMT
Cache-Control: no-cache
Server: Microsoft-IIS/6.0
X-AspNet-Version: 2.0.50727
content-disposition: attachment; filename="2006-05-31-12101
Pragma: no-cache
Via: 1.1 cbs-cache1 (NetCache NetApp/5.6.2R1)