Link to home
Start Free TrialLog in
Avatar of ctudorprice
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("content-disposition", "attachment; filename=""" & filename & """")
           
            Dim g As Integer = fi.LengthResponse.ContentType = "application/zip" 'tried application/x-zip-compressed too but makes no difference
           
             'Dim fi As New FileInfo(filename)
            'Response.AppendHeader("Content-Length", 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

ASKER CERTIFIED SOLUTION
Avatar of vinodhsomasekharan
vinodhsomasekharan

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of ctudorprice
ctudorprice

ASKER

As a follow-on to this question:

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-121013-properties.zip"
Pragma: no-cache
Via: 1.1 cbs-cache1 (NetCache NetApp/5.6.2R1)
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-properties.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-compressed 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(tempfilefullname)
            Response.AddHeader("Content-Length", file.Length.ToString()) ' this overrides the "Transfer-Encoding: chunked" which splits the file up and causes ie problems
            Response.AppendHeader("content-disposition", "attachment; filename=" & tempfilename)

            Response.WriteFile(tempfilefullname)
            Response.Flush()
            Response.End()

Hai,

That's good effort from u.. thanks for sharing the information.. really useful..


regards
Vinodh