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

ctudorpriceAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

vinodhsomasekharanCommented:
Hai,
           
It works fine for me.. try this

           fileStream = System.IO.File.Open(filename, IO.FileMode.Open, IO.FileAccess.Read,            IO.FileShare.Read)
            ReDim bytDocument(fileStream.Length)
            fileStream.Read(bytDocument, 0, fileStream.Length)

            Response.Clear()
            Response.AddHeader("content-disposition", "attachment; filename=""" & filename & """")
            Response.AddHeader("Content-Length", bytDocument.Length.ToString())
            Response.ContentType = "application/octet-stream"

            Response.BinaryWrite(bytDocument)
            Response.Flush()
            Response.Close()
            Response.End()




regards
Vinu


0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
ctudorpriceAuthor Commented:
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)
0
ctudorpriceAuthor Commented:
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()

0
vinodhsomasekharanCommented:
Hai,

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


regards
Vinodh
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
ASP.NET

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.