Connecting Tech Pros Worldwide Help | Site Map

Compressing a folder in c# ??

  #1  
Old December 30th, 2008, 08:51 AM
Newbie
 
Join Date: Dec 2008
Posts: 4
Hello All,

I am trying to compress a folder with different kinds of files and sub-folder programmatically. Googleing all the c# forums and news groups
(almost for half a day ) lead me to ICSharpCode SharpZipLib project. But I dont want to use this and I am trying to find out any other way to do this. Can anyone shed some light on this. I thought it must be easy to compress a folder in c#. Thank you.
  #2  
Old December 30th, 2008, 08:59 AM
Member
 
Join Date: Oct 2008
Posts: 50

re: Compressing a folder in c# ??


.NET framework has two classes that you can use for this
DeflateStream class (without CRC): DeflateStream Class (System.IO.Compression)
GZipStream (with CRC): GZipStream Class (System.IO.Compression)
  #3  
Old December 30th, 2008, 09:46 AM
Newbie
 
Join Date: Dec 2008
Posts: 4

re: Compressing a folder in c# ??


Thanks SvenV. Can you give me some example for compressing a folder.
  #4  
Old December 30th, 2008, 11:01 AM
nukefusion's Avatar
Expert
 
Join Date: Mar 2008
Location: Essex, UK
Posts: 197

re: Compressing a folder in c# ??


Quote:
Originally Posted by Eternal View Post
Thanks SvenV. Can you give me some example for compressing a folder.
Did you follow the links that SvenV provided? There is sample code there for compressing files including a link to a full blown application sample, also with source code that is capable of compressing multiple files.
  #5  
Old December 30th, 2008, 02:28 PM
PRR PRR is offline
Moderator
 
Join Date: Dec 2007
Location: India
Posts: 691
Provided Answers: 1

re: Compressing a folder in c# ??


Quote:
Originally Posted by Eternal View Post
Hello All,

I am trying to compress a folder with different kinds of files and sub-folder programmatically. Googleing all the c# forums and news groups
(almost for half a day ) lead me to ICSharpCode SharpZipLib project. But I dont want to use this and I am trying to find out any other way to do this. Can anyone shed some light on this. I thought it must be easy to compress a folder in c#. Thank you.
You could also use WMI to do so... Win32_Directory class
System.Management.
Expand|Select|Wrap|Line Numbers
  1. string filePath = @"C:\Zp1\Zp";
  2.             try
  3.             {
  4.                 ManagementObject dir =
  5.                     new ManagementObject("root\\CIMV2",  "Win32_Directory.Name='"+filePath+"'", null);
  6. ManagementBaseObject op = dir.InvokeMethod("Compress", null, null);
  7.  
  8. Console.WriteLine(op["ReturnValue"].Tostring);
  9. //0 for success
  10.  
  11.  
Win32_Directory
  #6  
Old December 31st, 2008, 08:21 AM
vekipeki's Avatar
Expert
 
Join Date: Nov 2007
Posts: 231

re: Compressing a folder in c# ??


There is a good open-source library which offers better compression compared to System.IO.Compression classes:

.NET Zip Library #ziplib (SharpZipLib)

There are several compression types (Zip, GZip, BZip2, Tar), with adjustable compression settings.
  #7  
Old December 31st, 2008, 01:18 PM
Newbie
 
Join Date: Dec 2008
Posts: 4

re: Compressing a folder in c# ??


Thank you all for the help.
Reply


Similar Threads
Thread Thread Starter Forum Replies Last Post
C# Programmatically Setting Permissions and Compressing a Folder (NTFS) steggun answers 2 July 12th, 2006 11:05 AM
Compressing folders in Windows using Python. sri2097 answers 6 January 1st, 2006 06:45 PM
IIS built-in compression Just D. answers 10 November 19th, 2005 07:39 AM
How to determine that if a folder is empty? could ildg answers 13 August 9th, 2005 11:55 PM