?
Solved

Downloading a Zip file to IE using conent-disposition

Posted on 2006-05-31
4
Medium Priority
?
624 Views
Last Modified: 2008-01-09
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

0
Comment
Question by:ctudorprice
  • 2
  • 2
4 Comments
 
LVL 5

Accepted Solution

by:
vinodhsomasekharan earned 2000 total points
ID: 16797187
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
 

Author Comment

by:ctudorprice
ID: 16797496
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
 

Author Comment

by:ctudorprice
ID: 16797965
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
 
LVL 5

Expert Comment

by:vinodhsomasekharan
ID: 16798172
Hai,

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


regards
Vinodh
0

Featured Post

How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article discusses the ASP.NET AJAX ModalPopupExtender control. In this article we will show how to use the ModalPopupExtender control, how to display/show/call the ASP.NET AJAX ModalPopupExtender control from javascript, how to show/display/cal…
Today is the age of broadband.  More and more people are going this route determined to experience the web and it’s multitude of services as quickly and painlessly as possible. Coupled with the move to broadband, people are experiencing the web via …
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…
Despite its rising prevalence in the business world, "the cloud" is still misunderstood. Some companies still believe common misconceptions about lack of security in cloud solutions and many misuses of cloud storage options still occur every day. …
Suggested Courses
Course of the Month13 days, 10 hours left to enroll

750 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question