Welcome to the Xceed Community Sign in | Join | Help
Community Search  

Zipping and unzipping a single file

Sort Posts: Previous Next
  •  05-21-2008, 7:30 AM Post no. 12398

    Zipping and unzipping a single file

    Hi,

    I am new to using Xceed and have spent most of the morning banging my head against a number of brick walls. I am trying to write some code that will allow me to zip/unzip a single file into/from an archive. I know that this should be very simple but I just can't get it to work properly regardless of how I try and do it. So far I have tried the following to get the file C:\file.txt zipped into an archive called c:\archive.zip. Any help ar advice would be greatly appreciated!

     
    Thanks,

     
    Ian

     


    1) QuickZip

    Code: 

    QuickZip.Zip(@"C:\archive.zip", @"C:\file.txt");

    Problem:

    This appears to be blocked by the corporate anti-virus software as I think it is trying to write into a temporary folder and doesn't have the correct permissions.

    Error:

    System.UnauthorizedAccessException was unhandled
      Message="Access to the path 'C:\\Documents and Settings\\All Users\\Application Data\\Symantec\\SRTSP\\SrtETmp' is denied."
      Source="Xceed.FileSystem"
      StackTrace:
           at Xceed.FileSystem.AbstractFolder.CopyFilesTo(FileSystemEvents events, Object userData, AbstractFolder destinationFolder, Boolean recursive, Boolean replaceExistingFiles, Object[] filters)
           at Xceed.FileSystem.AbstractFolder.CopyFilesTo(AbstractFolder destinationFolder, Boolean recursive, Boolean replaceExistingFiles, Object[] filters)
           at Xceed.Zip.QuickZip.Zip(String zipFileName, String encryptionPassword, Boolean replaceExistingFiles, Boolean recursive, Boolean preservePaths, String[] filesToZip)
           at Xceed.Zip.QuickZip.Zip(String zipFileName, String[] filesToZip) ...

     
    2)  From Martin Plante's blog 

     Took code from here but no archive was created at all: http://blogs.xceedsoft.com/plantem/PermaLink.aspx?guid=7b3858fb-3d0f-43d8-8beb-7252943d68f1

     

    My code: 

    AbstractFile zipFile = new DiskFile(@"C:\archive.zip");
    AbstractFile textFile = new ZippedFile(zipFile, @"C:\file.txt");


     3) From another online example:

    ZipEvents ze = new ZipEvents();
    DiskFile sourceFile = new DiskFile(@"C:\archive.zip");
    sourceFile.Create(ze, @"C:\file.txt");

     

    - creates an archive but there's nothing in it

     

     

  •  05-21-2008, 11:44 AM Post no. 12423 in reply to 12398

    Re: Zipping and unzipping a single file

    I'll make this very simple:

    With the FileSystem:

    //To zip
    AbstractFile zipFile = new DiskFile( @"C:\Archive.zip" );
    ZipArchive archive = new ZipArchive( zipFile );

    AbstractFile textFile = new DiskFile( @"C:\Test.txt" );
    textFile.CopyTo( archive, true );

    //To unzip all the archive's file
    AbstractFolder destinationFolder = new DiskFolder( @"C:\Destination" );
    archive.CopyFilesTo( destinationFolder, true, true, null );
    //To unzip the Test.txt file
    archive.CopyFilesTo( destinationFolder, true, true, "Test.txt" );

     

    Using QuickZip:

    QuickZip.Zip( @"C:\archive.zip", @"C:\Test.txt" );
    //You can modify the temp folder using this line
    ZipArchive.DefaultTempFolder = @"C:\TempFolder";
    QuickZip.Unzip( @"C:\archive.zip", @"C:\Destination", "*" );


    Charles Bérubé-Rémillard
    Technical Support
    Xceed Software Inc.
View as RSS news feed in XML
Contact | Site Map | Reviews | Legal Terms of Use | Trademarks | Privacy Statement Copyright 2008 Xceed Software Inc.