Compressing a folder in c# ?? 
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.
| 
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.
| 
December 30th, 2008, 11:01 AM
|  | Expert | | Join Date: Mar 2008 Location: Essex, UK
Posts: 197
| | | re: Compressing a folder in c# ?? Quote:
Originally Posted by Eternal 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.
| 
December 30th, 2008, 02:28 PM
| | Moderator | | Join Date: Dec 2007 Location: India
Posts: 691
Provided Answers: 1 | | | re: Compressing a folder in c# ?? Quote:
Originally Posted by Eternal 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. -
string filePath = @"C:\Zp1\Zp";
-
try
-
{
-
ManagementObject dir =
-
new ManagementObject("root\\CIMV2", "Win32_Directory.Name='"+filePath+"'", null);
-
ManagementBaseObject op = dir.InvokeMethod("Compress", null, null);
-
-
Console.WriteLine(op["ReturnValue"].Tostring);
-
//0 for success
-
-
Win32_Directory | 
December 31st, 2008, 08:21 AM
|  | 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.
| 
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.
|  | | | | /bytes/about
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 225,689 network members.
|