Click here to Skip to main content
15,895,827 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
please help me...

by using third party dll the code is :

C#
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Ionic.Zip;


namespace compression
{
    class Program
    {
        static void Main(string[] args)
        {
            using (var zip = new Ionic.Zip.ZipFile())
            {
                zip.AddDirectory("Stuff", "rootInZipFile");
                zip.Save("Stuff.zip");
            }
        }
    }
}
Posted

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 = @"D:\code.txt";
            string sZipFile = @"D:\code.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();
            }
        }
    }
}
 
Share this answer
 
Comments
Dhritirao's 28-Dec-12 2:05am    
thanks for u hellp
Dhritirao's 28-Dec-12 2:08am    
actually i need it has to compres upto 2gb.. i m getting error like this: The file is too long. This operation is currently limited to supporting files less than 2 gigabytes in size.
YES, you can compress folder(s) and file(s) without any third party tool.

.NET provides classes for compression in System.IO.Compression namespace.

Try it. best of luck...
 
Share this answer
 
Yes, you can compress file(s) and folder(s) using classes from System.IO.Compression namespace...
 
Share this answer
 
Comments
Dhritirao's 28-Dec-12 1:28am    
using System.IO.Compression;

i m using this but getting error like this


Error 1 'System.IO.FileStream' does not contain a definition for 'CopyTo' and no extension method 'CopyTo' accepting a first argument of type 'System.IO.FileStream' could be found (are you missing a using directive or an assembly reference?)

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