473,388 Members | 1,256 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,388 software developers and data experts.

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.
Dec 30 '08 #1
6 13467
SvenV
50
.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)
Dec 30 '08 #2
Thanks SvenV. Can you give me some example for compressing a folder.
Dec 30 '08 #3
nukefusion
221 Expert 100+
@Eternal
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.
Dec 30 '08 #4
PRR
750 Expert 512MB
@Eternal
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
Dec 30 '08 #5
vekipeki
229 Expert 100+
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.
Dec 31 '08 #6
Thank you all for the help.
Dec 31 '08 #7

Sign in to post your reply or Sign up for a free account.

Similar topics

6
by: Junkmail | last post by:
I have an application with highly compressable strings (gzip encoding usually does somewhere between 20-50X reduction.) My base 350MB database is mostly made up of these slowly (or even static)...
0
by: Yuancai \(Charlie\) Ye | last post by:
Hi, All: I am happy to annouce that we have formally released our latest SocketPro version 4 at www.udaparts.com, an advanced remoting framework written from batching/queue, asynchrony and...
13
by: could ildg | last post by:
I want to check if a folder named "foldername" is empty. I use os.listdir(foldername)== to do this, but it will be very slow if the folder has a lot of sub-files. Is there any efficient ways to do...
1
by: john smith | last post by:
Hi, In my .NET application I save data in an XML file. When opening a project from an XML file I parse the file and recreate objects, set settings etc. The problem is that the XML file can be...
6
by: sri2097 | last post by:
Hi, I'm trying to zip a particular fiolder and place the zipped folder into a target folder using python. I have used the following command in 'ubuntu'. zip_command = 'zip -qr %s %s' % (target,...
4
by: sri2097 | last post by:
Hi all,This is in reply to the 'Compressing folders in Windows using Python' query I raised y'day. I figured out that windows does not allow command line zipping so I started looking for...
2
by: steggun | last post by:
Hello, I'm writing a C# windows form application and need some guidance on a couple of issues. First, my application needs to change the permissions on a folder. The application creates a...
1
by: Jens Jensen | last post by:
Hello, I use the code below to zip files to a single .zip destination. I get the expected result when i work on my developement machine (WinXP sp.2). When i deploy the web application which...
3
by: msankardas | last post by:
Hi, As a part of my project, i need to compress folders and files into a single zip file as follows. for eg: I want to compress C:\test\ c:\compression\ C:\documents\test.txt
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.