Connecting Tech Pros Worldwide Help | Site Map

Compressing a folder in c# ??

 
LinkBack Thread Tools Search this Thread
  #1  
Old December 30th, 2008, 07:51 AM
Newbie
 
Join Date: Dec 2008
Posts: 4
Default Compressing a folder in c# ??

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.
Reply
  #2  
Old December 30th, 2008, 07:59 AM
Member
 
Join Date: Oct 2008
Posts: 50
Default

.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)
Reply
  #3  
Old December 30th, 2008, 08:46 AM
Newbie
 
Join Date: Dec 2008
Posts: 4
Default

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

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.
Reply
  #5  
Old December 30th, 2008, 01:28 PM
PRR's Avatar
PRR PRR is offline
Moderator
 
Join Date: Dec 2007
Location: The Matrix
Posts: 603
Default

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
Reply
  #6  
Old December 31st, 2008, 07:21 AM
vekipeki's Avatar
Expert
 
Join Date: Nov 2007
Posts: 230
Default

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.
Reply
  #7  
Old December 31st, 2008, 12:18 PM
Newbie
 
Join Date: Dec 2008
Posts: 4
Default

Thank you all for the help.
Reply
Reply

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search


Popular Articles

What is Bytes?

We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights. Get the best answers to your questions from over 220,840 network members.