Thursday, June 09, 2005

In the new package v1.2.5309 which will be available for download next week resides a new feature you won't see much emphasis about, but which I was very eager to complete. You can now create a ZipArchive instance around an AbstractFile that does not support reading from.

(drum roll) ... (looking around) ... Nobody's applauding? That's because you probably don't know yet how useful this can be.

Most ASP.NET applications that wish to create zip files on the fly and send them in the response are either stuck with creating those zip files on disk in a temporary filename, or create them in a MemoryFile, then copy that MemoryFile in the response stream.

However, the StreamFile class was created for such purposes of exposing any existing Stream as an AbstractFile. You already could create a StreamFile around the Response's OutputStream. But passing that StreamFile to the ZipArchive's constructor would fail, because it can't read from it. Instead of assuming an empty zip file, it miserably failed. Shame.

No more... Since version 2.2.5302, it will assume the zip file is empty. So code like this works perfectly:

    public void ProcessRequest(HttpContext context)
    {
      context.Response.ContentType = "application/zip";
      context.Response.AddHeader( "Content-Disposition", "attachment; filename=images.bmp" );
 
      ZipArchive archive = new ZipArchive( new StreamFile( context.Response.OutputStream ) );
      DiskFolder source = new DiskFolder( context.Request.MapPath( "." ) );
 
      source.CopyFilesTo( archive, false, false, "*.bmp" );
    }

The same problem appeared when trying to combine Xceed Zip for .NET with Xceed FTP for .NET, to upload zip files directly on the FTP server. Though the FtpClient class exposes a very useful GetUploadStream method to get a direct stream on the data connection, code like this previously failed.

          using( Stream upload = client.GetUploadStream( "images.zip" ) )
          {
            ZipArchive archive = new ZipArchive( new StreamFile( upload ) );
            DiskFolder source = new DiskFolder( @"d:\images\" );
 
            source.CopyFilesTo( archive, false, false, "*.bmp" );
          }

Talk about short and sweet uploads of zip files!


.NET | FileSystem | FTP | Zip

6/9/2005 2:56:43 PM (Eastern Daylight Time, UTC-04:00)  #   
Tracked by:
"midi colonna sonore" (midi colonna sonore) [Trackback]
"jhonny depp" (jhonny depp) [Trackback]
"albergo bournemouth" (albergo bournemouth) [Trackback]
"londra big ben" (londra big ben) [Trackback]
"memory card" (memory card) [Trackback]
"calendario 2003" (calendario 2003) [Trackback]
"bionde masturbandosi" (bionde masturbandosi) [Trackback]
"MUSIC - Bethlehem Morning" (MUSIC - Bethlehem Morning) [Trackback]
"gioco scaricare gratis pc" (gioco scaricare gratis pc) [Trackback]
"vacanza ad ischia" (vacanza ad ischia) [Trackback]
"immagini disney" (immagini disney) [Trackback]
"new york four seasons hotel" (new york four seasons hotel) [Trackback]
"Steve Brock Ministries" (Steve Brock Ministries) [Trackback]
"giochi carta regolamento" (giochi carta regolamento) [Trackback]
"scuola superiore" (scuola superiore) [Trackback]
"val d aosta" (val d aosta) [Trackback]
"gioco adulto gratis" (gioco adulto gratis) [Trackback]
"freddissimo gradito papa" (freddissimo gradito papa) [Trackback]
"amministratore condominiale" (amministratore condominiale) [Trackback]
"medio apparecchio" (medio apparecchio) [Trackback]
"albergo firenze hotel" (albergo firenze hotel) [Trackback]
"PRODUCTS" (PRODUCTS) [Trackback]
"l attimo fuggente" (l attimo fuggente) [Trackback]
"torte bindi" (torte bindi) [Trackback]
"perline gioiello" (perline gioiello) [Trackback]
"Steve Brock Ministries" (Steve Brock Ministries) [Trackback]
"MUSIC - Gloria" (MUSIC - Gloria) [Trackback]
"pulcino fottilo nella residenza" (pulcino fottilo nella residenza) [Trackback]
"Steve Brock Ministries" (Steve Brock Ministries) [Trackback]
"Steve Brock Ministries" (Steve Brock Ministries) [Trackback]
"MUSIC - Mary Did You Know/What Child Is This?" (MUSIC - Mary Did You Know/What ... [Trackback]
"Steve Brock Ministries" (Steve Brock Ministries) [Trackback]
"HOME" (HOME) [Trackback]
"PHOTOS" (PHOTOS) [Trackback]
"MUSIC" (MUSIC) [Trackback]
"PARTNERS" (PARTNERS) [Trackback]
"OUTREACH" (OUTREACH) [Trackback]
"SCHEDULE" (SCHEDULE) [Trackback]
"CONTACT" (CONTACT) [Trackback]
"mediale affari" (mediale affari) [Trackback]