Home Forums .NET libraries Xceed Zip & Real-Time Zip for .NET Can Xceed Zip for .NET generate files from byte arrays?

Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • User (Old forums)
    Member
    Post count: 23064
    #19641 |

    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
    Case “DOC”
    Response.ContentType = “application/msword”
    Case “RTF”
    Response.ContentType = “application/rtf”
    Case “PDF”
    Response.ContentType = “application/pdf”
    End Select

    Response.Clear()
    Response.OutputStream.Write(MyData, 0, CvrSize)
    Response.Flush()
    Response.End()

    Imported from legacy forums. Posted by Steve (had 3002 views)

    Xceed Support
    Member
    Post count: 5658

    Hi emoticon,

    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)

    User (Old forums)
    Member
    Post count: 23064

    Perfect! Thanks so much.

    Imported from legacy forums. Posted by Steve (had 3577 views)

Viewing 3 posts - 1 through 3 (of 3 total)
  • You must be logged in to reply to this topic.