Click here to Skip to main content
Click here to Skip to main content
Alternative Tip

Tagged as

Go to top

How to compress/decompress directories using GZipStream

, 4 Feb 2012
Rate this:
Please Sign up or sign in to vote.
Note this code will not unzip general zip files. It only works with files zipped according to the package standard.To unzip regular zip files, there are several components available.I've used the Windows built-in COM component "Microsoft Shell Controls And Automation" (Add Reference, COM...
Note this code will not unzip general zip files. It only works with files zipped according to the package standard.
 
To unzip regular zip files, there are several components available.
 
I've used the Windows built-in COM component "Microsoft Shell Controls And Automation" (Add Reference, COM tab).
 
The code to unzip using this component is:
using Shell32;
 
static void Unzip(string zipFile, string directory) {
  ShellClass sc = new ShellClass();
  Folder source = sc.NameSpace(zipFile);
  Folder target = sc.NameSpace(directory);
  FolderItems items = source.Items();
  const int options = (int)(CopyOptions.NoProgressDialog | CopyOptions.YesToAll);
  target.CopyHere(items, options);
}
Where the enum values are:
[Flags]
internal enum CopyOptions {
  /// <summary>Do not display a progress dialog box.</summary>
  NoProgressDialog = 4,
  /// <summary>Rename the target file if a file exists at the target location with the same name.</summary>
  RenameDuplicates = 8,
  /// <summary>Click "Yes to All" in any dialog box displayed.</summary>
  YesToAll = 16,
  /// <summary>Preserve undo information, if possible.</summary>
  PreserveUndo = 64,
  /// <summary>Perform the operation only if a wildcard file name (*.*) is specified.</summary>
  AcceptWildcardOnly = 128,
  /// <summary>Display a progress dialog box but do not show the file names.</summary>
  ProgressDialogWithoutFilenames = 256,
  /// <summary>Do not confirm the creation of a new directory if the operation requires one to be created.</summary>
  CreateDirectoryWithoutDialog = 512,
  /// <summary>Do not display a user interface if an error occurs.</summary>
  NoDialogOnError = 1024,
  /// <summary>Disable recursion.</summary>
  NoRecursion = 4096,
  /// <summary>Do not copy connected files as a group. Only copy the specified files.</summary>
  OnlySpecifiedFiles = 8192
}
Cheers,
Michel

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Share

About the Author

msmits
Architect Independer
Netherlands Netherlands
No Biography provided

Comments and Discussions

 
-- There are no messages in this forum --
| Advertise | Privacy | Mobile
Web03 | 2.8.140916.1 | Last Updated 4 Feb 2012
Article Copyright 2012 by msmits
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid