Chilkat
HOME
Android™
ASP
Visual Basic
VB.NET
C#
iOS (IPhone)
Objective-C
C++
C
MFC
Delphi
FoxPro
Java
Perl
PHP Extension
PHP ActiveX
Python
PowerShell
Ruby
SQL Server
VBScript
Write Zip to ASP.NET Response
Demonstrates how to write a .zip file to the ASP.NET Response object in VB.NET. The "Zip" variable is a Chilkat.Zip object. It could have loaded a .zip file, or created a .zip dynamically in memory via AppendData or AppendString/AppendAnsi methods. Regardless, the point of this example is to show how to send the zip file to the ASP.NET response. The Zip.WriteToMemory method writes the zip file to an in-memory byte array, and this is written to the Response via BinaryWrite. 'Return atached file
Dim Data As Byte()
Data = Zip.WriteToMemory
Response.Clear()
Response.ContentType = "application/octet-stream"
Response.AddHeader("Content-Length",Data.Length.ToString())
Response.AddHeader("Content-Disposition", _
"attachment; filename=""" & Zip.FileName & """")
Response.Flush()
Response.BinaryWrite(Data)
'The reason Im using "application/octet-stream" is to force
'the Open, Save, Cancel dialog box to popup. For the above code to work
'correctly, Ive had to include the following override:
Protected Overrides Sub Render(ByVal writer As System.Web.UI.HtmlTextWriter)
'Do nothing... I've added this to prevent the normal rendering of pages from
'happening. Even though I was clearing the content from the render stream,
'it was STILL being sent downstream and FUBARing my returned files.
End Sub
|
© 2000-2012 Chilkat Software, Inc. All Rights Reserved.