Click here to Skip to main content
15,892,005 members
Please Sign up or sign in to vote.
1.00/5 (4 votes)
See more:
string path = createzip(txtnum.Text.ToString());
DirectoryInfo dir = new DirectoryInfo(path);
FileInfo[] zip = dir.GetFiles("*.zip");
if (zip[0].FullName != null)
{
using (FileStream target = new FileStream(zip[0].FullName, FileMode.Create, FileAccess.Write))
using (GZipStream alg = new GZipStream(target, CompressionMode.Compress))
{
byte[] data = File.ReadAllBytes(zip[0].FullName);
alg.Write(data, 0, data.Length);
alg.Flush();

}
}
Posted
Updated 8-Jan-15 0:41am
v2
Comments
Praveen Kumar Upadhyay 8-Jan-15 6:44am    
What is your question?
sheena k 8-Jan-15 6:52am    
how to reduce the .zip file size ???
right now its size in MB I want to reduce it into KB...can u help me ??
Richard MacCutchan 8-Jan-15 7:01am    
You cannot reduce its size; it is already compressed.
sheena k 8-Jan-15 7:04am    
@Richard : yes its already compressed but little bit difference coming by using this way....I want another method to reduce file upto 70%
Richard MacCutchan 8-Jan-15 7:10am    
What part of "You cannot reduce its size; it is already compressed." do you not understand? If the data is compressed then you cannot compress it any more.

You can't, not necessarily - it depends on what the file holds how much it can be compressed without losing data. Some file formats compress well: XLSX files for example are XML (largely text) based and tend to compress well, while AVI files are already compressed and there isn't a lot you can do.

Certainly, you can't guarantee to compress "any file" by any amount - and some files may get larger after compression as a result of the overheads of compression!

But if it can be done, then look at SharpZipLib[^] or similar.
 
Share this answer
 
I suggest you study the difference between "losless compression" and "lossy compression," and get clear which one you want to use in a given situation.

And, be aware that a given file has a certain limit to how much it can be compressed losslessly by any specific method of compression (Zip, WinRar, 7-Zip, etc.): I have seen some files that losslessly compressed by a factor of 25% smaller in WinRar than with Zip, and other files that had only slight differences.

If the file is encoded, encrypted, natively compressed (as are bitmap files in general ... .jpg, .png, etc., and audio, and vidoe files, etc.) then further compression is usually useless.

.flac is an example of a music file format which is lossless, but still can compress to some degree.

.jpg is, of course, a lossy compression method, with the compression factor a variable you can set. .png is lossless, except that by altering the bit-depth of the color-palette you can change the size of the file: of course, if you lower the bit-depth of the palette you will potentially lose color information.
 
Share this answer
 
v2

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900