none
SSIS zip files RRS feed

  • Question

  • Hi,

    Without installing a 3rd party tool such as Winzip or 7zip, is there a way to have SSIS automatically zip files? 

    I thought there might be a way using .net code (either VB or C#), but i can't find anything out there.

    Any help would be appreciated.

    Thanks,
    Scott
    Sunday, December 19, 2010 7:47 PM

Answers

  • Literally just did this last week as no-one seems to show how to utilise the winXP zip functionality

    As that link suggests, GZip is available to .NET - I use this function to compress a file:

    Imports System.IO.Compression
    Public Sub Compress(ByVal FilePath As String) 
     Dim UncompressedData As Byte() = System.IO.File.ReadAllBytes(FilePath) 
     Dim CompressedData As New MemoryStream() 
     Dim GZipper As New GZipStream(CompressedData, CompressionMode.Compress, True) 
     GZipper.Write(UncompressedData, 0, UncompressedData.Length)
    GZipper.Dispose()
    System.IO.File.WriteAllBytes(Left(FilePath, InStr(FilePath, ".") - 1) + ".gz", CompressedData.ToArray)
    CompressedData.Dispose()
    End Sub

     

     

    the main issue with this is that the "zipped" files are not readable natively in windows - you can download winzip to open them or you can use 7-Zip (freeware). Either will allow you to re-open the files from windows explorer. you can of course code the extraction of files through .NET as well but as you're asking in an SSIS forum I'm guessing you're more concerned with the archiving of files rather than extracting them again


    Rgds Geoff

    Sunday, December 19, 2010 11:34 PM

All replies

  • Hi,

    Try using the following within a SSIS script component; - http://forums.asp.net/p/1086292/1743179.aspx

    Kind Regards,

    Kieran.


    If you have found any of my posts helpful then please vote them as helpful. Kieran Wood MCTS BI, PGD SoftDev (Open), MBCS http://uk.linkedin.com/in/bileeds
    Sunday, December 19, 2010 7:57 PM
  • Literally just did this last week as no-one seems to show how to utilise the winXP zip functionality

    As that link suggests, GZip is available to .NET - I use this function to compress a file:

    Imports System.IO.Compression
    Public Sub Compress(ByVal FilePath As String) 
     Dim UncompressedData As Byte() = System.IO.File.ReadAllBytes(FilePath) 
     Dim CompressedData As New MemoryStream() 
     Dim GZipper As New GZipStream(CompressedData, CompressionMode.Compress, True) 
     GZipper.Write(UncompressedData, 0, UncompressedData.Length)
    GZipper.Dispose()
    System.IO.File.WriteAllBytes(Left(FilePath, InStr(FilePath, ".") - 1) + ".gz", CompressedData.ToArray)
    CompressedData.Dispose()
    End Sub

     

     

    the main issue with this is that the "zipped" files are not readable natively in windows - you can download winzip to open them or you can use 7-Zip (freeware). Either will allow you to re-open the files from windows explorer. you can of course code the extraction of files through .NET as well but as you're asking in an SSIS forum I'm guessing you're more concerned with the archiving of files rather than extracting them again


    Rgds Geoff

    Sunday, December 19, 2010 11:34 PM
  • Geoff's post looks very useful to me.
    If you have found any of my posts helpful then please vote them as helpful. Kieran Wood MCTS BI, PGD SoftDev (Open), MBCS http://uk.linkedin.com/in/bileeds
    Tuesday, December 21, 2010 9:40 AM
  • You can use SharpZipLib  

    using ICSharpCode.SharpZipLib.Zip;
    
    
    
    	string targetFolder = Dts.Variables["XMLA_Folder_Target"].Value.ToString();
    	string zipFileName = targetFolder + "XMLA_Archive.zip";
      FastZip fZip = new FastZip();
    
      fZip.CreateZip(zipFileName, targetFolder, false, "Files_.*.txt");
    

    Here's an article that will give you more options in using the library:

     

    Compressing and uncompressing ZIP files

     

    Regards,

    Jason


    MCITP BI Developer 2008 - MCTS SQL Server 2005
    Tuesday, December 21, 2010 12:26 PM
  • Hi,

    Without installing a 3rd party tool such as Winzip or 7zip, is there a way to have SSIS automatically zip files? 

    I thought there might be a way using .net code (either VB or C#), but i can't find anything out there.

    Any help would be appreciated.

    Thanks,
    Scott


    The only method is to use the .net comression class: http://msdn.microsoft.com/en-en/library/system.io.compression.aspx, but that only works with gzip. Zip is not supported. You can install Microsoft Visual J# Redistributable Packages (Is Microsoft, so not really third party) and use that dll to zip your files with a Script Task. Here is a C# example: http://microsoft-ssis.blogspot.com/2011/01/zip-sourcefile-to-archive.html

    Saturday, January 8, 2011 10:09 AM
    Moderator