Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C#
using System;
using System.Collections.Generic;
using System.Text;
using System.IO;
using System.IO.Compression;
 
namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            string sFileToZip = @"C:\MyDocuments\123.txt";
            string sZipFile = @"C:\MyDocuments\123.zip";
 
            using (FileStream __fStream = File.Open(sZipFile, FileMode.Create))
            {
                GZipStream obj = new GZipStream(__fStream, CompressionMode.Compress);
 
                byte[] bt = File.ReadAllBytes(sFileToZip);
                obj.Write(bt, 0, bt.Length);
 
                obj.Close();
                obj.Dispose();
            }
        }
    }
}
Posted 27-Dec-12 20:14pm
Comments
Sergey Alexandrovich Kryukov at 28-Dec-12 2:16am
   
How about third-party source code, even better quality than 1st party, would not mind? :-)
—SA
dhritirao1221 at 28-Dec-12 2:20am
   
actually ididnt get u, but what i mean to say is i have already worked the same with using third party dll i.e using ionic but now my t.l want to work me with out using any third party dll. but as per the above i m able to Zip for very less size files. i need it for upto 2gb
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

Hi,
 
Use DotNetZip (http://dotnetzip.codeplex.com/[^])
 
it will solve your problem. Smile | :)
 
[Update]
If you don't want to download any thing then try this : Compress Zip files with Windows Shell API and C#[^]
  Permalink  
v2
Comments
dhritirao1221 at 28-Dec-12 2:22am
   
i dnot want to downlaod any libraries
Suvabrata Roy at 28-Dec-12 2:27am
   
Its Free, you can freely used it in your project.
dhritirao1221 at 28-Dec-12 4:15am
   
ya i to know its free of cost. but without using those is there any possibility i asked.
Suvabrata Roy at 28-Dec-12 4:46am
   
http://www.codeproject.com/Articles/12064/Compress-Zip-files-with-Windows-Shell-API-and-C
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

The thing is: GZip is not zip. This is a different compression format.
 
To work with ZIP, you can use #ziplib:
http://www.icsharpcode.net/opensource/sharpziplib/[^].
 
Another option is using SevenZipSharp, a .NET wrapper of the famous 7-Zip:
http://en.wikipedia.org/wiki/7-Zip[^],
http://sevenzipsharp.codeplex.com/[^].
 
Both ZIP libraries are open-source. So, you won't have to use any "3rd-party DLLs".
 
—SA
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 3

  Permalink  
Comments
dhritirao1221 at 28-Dec-12 4:14am
   
ok thanks for ur help
ProgramFOX at 28-Dec-12 7:46am
   
You're welcome!

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

  Print Answers RSS
0 Sergey Alexandrovich Kryukov 746
1 OriginalGriff 345
2 Magic Wonder 131
3 Kishore Pogaru 130
4 Fredrik Bornander 130
0 OriginalGriff 5,705
1 Sergey Alexandrovich Kryukov 4,763
2 CPallini 4,570
3 George Jonsson 3,142
4 Gihan Liyanage 2,450


Advertise | Privacy | Mobile
Web03 | 2.8.140916.1 | Last Updated 28 Dec 2012
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100