User (Old forums)MemberAugust 8, 2006 at 8:08 pmPost count: 23064
I have a database driven application where users can click on a link and download files from SQL Server. The files are stored as binary data in SQL Server. Once the user clicks, the link the binary data is downloaded and sent to the user in the HTTP stream where the user can save or open the file.
If I continually generate files, can I store them in a zip file instead of flushing them to the browser? In other words, I want to grab multiple binary files from SQL by looping and save each one at a time to a zip file. The zip file would then be storable on the user’s hard drive.
Below is working code that takes a stream of binary data from a db and creates a file that is flushed to the browser. Can this code be tweaked to do what I need?
Dim MyData() As Byte
‘myrow.coverletter contains binary data from sql server. It could be pdf,rtf or word
MyData = myRow.CoverLetter
‘what is the file type?
Dim CvrFileType As String = myRow.CoverType
‘what is the size in bytes?
Dim CvrSize As Integer = myRow.CoverLength
Response.Buffer = True
Dim theFileName As String = myRow.FirstName & ” ” & myRow.LastName & ” Cover Letter Job ” & myRow.jobID.Trim & “.” & myRow.CoverType.ToLower
Response.AddHeader(“Content-Disposition”, “attachment;filename=” & theFileName)
Select Case CvrFileType.ToUpper
Response.ContentType = “application/msword”
Response.ContentType = “application/rtf”
Response.ContentType = “application/pdf”
Response.OutputStream.Write(MyData, 0, CvrSize)
Imported from legacy forums. Posted by Steve (had 3002 views)Xceed SupportMemberAugust 9, 2006 at 2:35 pmPost count: 5658
I’m not sure I understand exactly what you want to do but one thing you can do is to create a MemoryStream around your byte array, create a StreamFile using the MemoryStream and then copy this StreamFile into your archive. Here’s a code example for this procedure:
‘Creates a MemoryStream around the byte array from the database
Dim stream as MemoryStream = new MemoryStream( MyData )
‘Creates a StreamFile object which expose a stream as a file compatible with Xceed’s FileSystem.
Dim file as StreamFile = new StreamFile( stream )
‘We will use a file on disk as our zip file. This can be any AbstractFile. (memory, Ftp, etc)
Dim zipFile DiskFile = new DiskFile( “C:\MyZip.zip” );
Dim ZipArchive archive = new ZipArchive( zipFile )
‘Copy the StreamFile into the archive.
file.CopyTo( archive, true )
Is this what you were looking for?
Hope this help!
Imported from legacy forums. Posted by Jacques [Xceed] (had 322 views)
- You must be logged in to reply to this topic.