ComponentSoft.net Ultimate ZIP http://www.zipcomponent.net How to use ZIP Component in C#, VB.NET and ASP.NET posterous.com Sun, 20 Mar 2011 20:54:00 -0700 Listing contents of an archive http://www.zipcomponent.net/listing-contents-of-an-archive http://www.zipcomponent.net/listing-contents-of-an-archive

This topic demonstrates how to get a listing of all of the files stored within an archive.

To list the files stored within an archive, you need to perform the following steps:

  1. Create a new Zip object.
  2. Open an existing archive file or create a new archive using Open methods.
  3. Call ListAll or ListDirectory to retrieve the desired list of file information within the archive.

This example shows how to list all files stored within an archive:

C#:

using System; using Atp.Compression; using Atp.IO; namespace CSharp {    static class ListAll    {        [STAThread]        static void Main()        {            // Open an existing file            Zip zip = new Zip("test.zip");            // List .doc files.            ZipFileInfoCollection col = zip.ListAll("*.doc");            foreach (ZipFileInfo archiveFile in col)            {                Console.WriteLine("File Name: " + archiveFile.Name);                Console.WriteLine("    Last Write Time: " + archiveFile.LastWriteTime.ToShortDateString() + " " +                    archiveFile.LastWriteTime.ToShortTimeString());                Console.WriteLine("    Uncompressed Size: " + archiveFile.Length);                Console.WriteLine("    Compressed Size: " + archiveFile.CompressedLength);                Console.WriteLine("    Compression Rate: " + archiveFile.CompressionRate);                Console.WriteLine("    CRC: " + archiveFile.Checksum);                Console.WriteLine("    Stored Path: " + archiveFile.DirectoryPath);                Console.WriteLine("    Comment: " + archiveFile.Comment);            }            // List files with zero length.            col = zip.ListAll(SearchCondition.SizeEqualTo(0L));            foreach (ZipFileInfo archiveFile in col)            {                Console.WriteLine("File Name: " + archiveFile.Name);                Console.WriteLine("    Last Write Time: " + archiveFile.LastWriteTime.ToShortDateString() + " " +                    archiveFile.LastWriteTime.ToShortTimeString());                Console.WriteLine("    Uncompressed Size: " + archiveFile.Length);                Console.WriteLine("    Compressed Size: " + archiveFile.CompressedLength);                Console.WriteLine("    Compression Rate: " + archiveFile.CompressionRate);                Console.WriteLine("    CRC: " + archiveFile.Checksum);                Console.WriteLine("    Stored Path: " + archiveFile.DirectoryPath);                Console.WriteLine("    Comment: " + archiveFile.Comment);            }            // List all files.            col = zip.ListAll();            foreach (ZipFileInfo archiveFile in col)            {                Console.WriteLine("File Name: " + archiveFile.Name);                Console.WriteLine("    Last Write Time: " + archiveFile.LastWriteTime.ToShortDateString() + " " +                    archiveFile.LastWriteTime.ToShortTimeString());                Console.WriteLine("    Uncompressed Size: " + archiveFile.Length);                Console.WriteLine("    Compressed Size: " + archiveFile.CompressedLength);                Console.WriteLine("    Compression Rate: " + archiveFile.CompressionRate);                Console.WriteLine("    CRC: " + archiveFile.Checksum);                Console.WriteLine("    Stored Path: " + archiveFile.DirectoryPath);                Console.WriteLine("    Comment: " + archiveFile.Comment);            }            zip.Close();        }    } }

VB.NET

Imports Microsoft.VisualBasic Imports System Imports Atp.Compression Imports Atp.IO Module ListAll     Sub Main()         ' Open an existing file         Dim zip As New Zip("test.zip")         ' List .doc files.         Dim col As ZipFileInfoCollection = zip.ListAll("*.doc")         For Each archiveFile As ZipFileInfo In col             Console.WriteLine("File Name: " & archiveFile.Name)             Console.WriteLine(" Last Write Time: " & archiveFile.LastWriteTime.ToShortDateString() & " " & archiveFile.LastWriteTime.ToShortTimeString())             Console.WriteLine(" Uncompressed Size: " & archiveFile.Length)             Console.WriteLine(" Compressed Size: " & archiveFile.CompressedLength)             Console.WriteLine(" Compression Rate: " & archiveFile.CompressionRate)             Console.WriteLine(" CRC: " & archiveFile.Checksum)             Console.WriteLine(" Stored Path: " & archiveFile.DirectoryPath)             Console.WriteLine(" Comment: " & archiveFile.Comment)         Next archiveFile         ' List files with zero length.         col = zip.ListAll(SearchCondition.SizeEqualTo(0L))         For Each archiveFile As ZipFileInfo In col             Console.WriteLine("File Name: " & archiveFile.Name)             Console.WriteLine(" Last Write Time: " & archiveFile.LastWriteTime.ToShortDateString() & " " & archiveFile.LastWriteTime.ToShortTimeString())             Console.WriteLine(" Uncompressed Size: " & archiveFile.Length)             Console.WriteLine(" Compressed Size: " & archiveFile.CompressedLength)             Console.WriteLine(" Compression Rate: " & archiveFile.CompressionRate)             Console.WriteLine(" CRC: " & archiveFile.Checksum)             Console.WriteLine(" Stored Path: " & archiveFile.DirectoryPath)             Console.WriteLine(" Comment: " & archiveFile.Comment)         Next archiveFile         ' List all files.         col = zip.ListAll()         For Each archiveFile As ZipFileInfo In col             Console.WriteLine("File Name: " & archiveFile.Name)             Console.WriteLine(" Last Write Time: " & archiveFile.LastWriteTime.ToShortDateString() & " " & archiveFile.LastWriteTime.ToShortTimeString())             Console.WriteLine(" Uncompressed Size: " & archiveFile.Length)             Console.WriteLine(" Compressed Size: " & archiveFile.CompressedLength)             Console.WriteLine(" Compression Rate: " & archiveFile.CompressionRate)             Console.WriteLine(" CRC: " & archiveFile.Checksum)             Console.WriteLine(" Stored Path: " & archiveFile.DirectoryPath)             Console.WriteLine(" Comment: " & archiveFile.Comment)         Next archiveFile         zip.Close()     End Sub End Module

Permalink | Leave a comment  »

]]>
http://files.posterous.com/user_profile_pics/793593/RawLogo.png http://posterous.com/users/5AqhTle47UWJ ComponentSoft.net ATP Inc ComponentSoft.net
Sun, 26 Sep 2010 23:41:00 -0700 Optimizing speed by using the transaction system http://www.zipcomponent.net/componentsoft-zip-optimize-speed-by-using-the http://www.zipcomponent.net/componentsoft-zip-optimize-speed-by-using-the

UltimateZip introduces the Transaction System which helps speed up performing multiple operations on files and folders. You can use the BeginUpdate, CancelUpdate, EndUpdate methods and InUpdate property of the Zip class to optimize speed of executing the archive updating operations.

In the setup package, we have a sample project named Transaction that demonstrates how to use Ultimate Zip library to speed up the file compression process.

Ultimate ZIP Transaction

The following example shows how to use the BeginUpdate method to initiate the transaction system, EndUpdate to commit changes and CancelUpdate to rollback changes when an error occurs. Before using the class, please remember adding references to the required assemblies as well as using directive for namespace Atp.Compression.

After adding the using directive, you can create a new instance of the Zip class, call the BeginUpdate method, add files to the archive, and then end the transaction with the EndUpdate method.

Using Transaction System in Ultimate Zip

C#  
    static class TransactionSystem
   {
       [STAThread]
       
static void Main()
       {
           
// Open an existing file.
           
Zip zip = new Zip("c:\\test.zip");

                      // Begin transaction.
           
zip.BeginUpdate();
           
try
           {   
               
// Add all .txt files
               
zip.AddFiles("c:\\test", "", "*.txt");
           }
           
catch (Exception)
           {
               
// Cancel the transaction if an error occurs.
               
zip.CancelUpdate();
           }
           
// Close the zip file.
           
zip.EndUpdate();
           zip.Close();
       }
   }

VB.NET  
Module TransactionSystem
    Sub Main()
        ' Open an existing file.
        Dim zip As New Zip("c:\test.zip")
        ' Begin transaction.
        zip.BeginUpdate()
        Try
            ' Add all .txt files
            zip.AddFiles("c:\test", "", "*.txt")
        Catch e1 As Exception
            ' Cancel the transaction if an error occurs.
            zip.CancelUpdate()
        End Try
        ' Close the zip file.
        zip.EndUpdate()
        zip.Close()
    End Sub
End Module

For more details on adding files and folders to an archive, see this topic. The topic demonstrates using the AddFiles method to compress files and folders with the Ultimate compression zip library. You can also use the CopyFrom and CopyTo methods to transfer files from/to another file system. Supports file systems are FTP, SFTP, SCP, Disk, and Virtual File Systems.

Permalink | Leave a comment  »

]]>
http://files.posterous.com/user_profile_pics/793593/RawLogo.png http://posterous.com/users/5AqhTle47UWJ ComponentSoft.net ATP Inc ComponentSoft.net
Sat, 19 Jun 2010 14:49:00 -0700 How to add files and folders to an archive http://www.zipcomponent.net/how-to-add-files-and-folders-to-an-archive http://www.zipcomponent.net/how-to-add-files-and-folders-to-an-archive

This topic demonstrates how to add files and folders to an archive using Ultimate Zip component. To add files and folders to an archive, you need to perform the following steps:

  1. Specify a folder path whose files will be added to the archive.
  2. Retrieve a reference to a new or existing archive file using the Zip class.
  3. Call AddFile or AddFiles methods to copy or move existing files to the archive.

See the following example more more details:

C#

// Create a new instance. Zip zip = new Zip(); // Create a new zip file. zip.Create("test.zip"); // Set password zip.EncryptionAlgorithm = EncryptionAlgorithm.PkzipClassic; zip.Password = "password"; // Add all files and subdirectories from 'c:\test' to the archive. zip.AddFiles(@"c:\test"); // Add all files and subdirectories from 'c:\my folder' to the archive. zip.AddFiles(@"c:\my folder", ""); // Add all files and subdirectories from 'c:\my folder' to '22' folder within the archive. zip.AddFiles(@"c:\my folder2", "22"); // Add all .dat files from 'c:\my folder' to '22' folder within the archive. zip.AddFiles(@"c:\my folder2", "22", "*.dat"); // Or simply use this to add all .dat files from 'c:\my folder' to '22' folder within the archive. zip.AddFiles(@"c:\my folder2\*.dat", "22"); // Add *.dat and *.exe files from 'c:\my folder' to '22' folder within the archive. zip.AddFiles(@"c:\my folder2\*.dat;*.exe", "22"); // Close the zip file. zip.Close();

VB.NET

' Create a new instance. Dim zip As New Zip() ' Create a new zip file. zip.Create("test.zip") ' Set password zip.EncryptionAlgorithm = EncryptionAlgorithm.PkzipClassic zip.Password = "password" ' Add all files and subdirectories from 'c:\test' to the archive. zip.AddFiles("c:\test") ' Add all files and subdirectories from 'c:\my folder' to the archive. zip.AddFiles("c:\my folder", "") ' Add all files and subdirectories from 'c:\my folder' to '22' folder within the archive. zip.AddFiles("c:\my folder2", "22") ' Add all .dat files from 'c:\my folder' to '22' folder within the archive. zip.AddFiles("c:\my folder2", "22", "*.dat") ' Or simply use this to add all .dat files from 'c:\my folder' to '22' folder within the archive. zip.AddFiles("c:\my folder2\*.dat", "22") ' Add *.dat and *.exe files from 'c:\my folder' to '22' folder within the archive. zip.AddFiles("c:\my folder2\*.dat;*.exe", "22") ' Close the zip file. zip.Close()

Permalink | Leave a comment  »

]]>
http://files.posterous.com/user_profile_pics/793593/RawLogo.png http://posterous.com/users/5AqhTle47UWJ ComponentSoft.net ATP Inc ComponentSoft.net