Click here to Skip to main content
15,895,667 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
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
Comments
Sergey Alexandrovich Kryukov 28-Dec-12 2:16am    
How about third-party source code, even better quality than 1st party, would not mind? :-)
—SA
Dhritirao's 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

Hi,

Use DotNetZip (http://dotnetzip.codeplex.com/[^])

it will solve your problem. :)

[Update]
If you don't want to download any thing then try this : Compress Zip files with Windows Shell API and C#[^]
 
Share this answer
 
v2
Comments
Dhritirao's 28-Dec-12 2:22am    
i dnot want to downlaod any libraries
Suvabrata Roy 28-Dec-12 2:27am    
Its Free, you can freely used it in your project.
Dhritirao's 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 28-Dec-12 4:46am    
http://www.codeproject.com/Articles/12064/Compress-Zip-files-with-Windows-Shell-API-and-C
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
 
Share this answer
 
 
Share this answer
 
Comments
Dhritirao's 28-Dec-12 4:14am    
ok thanks for ur help
Thomas Daniels 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)



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