Click here to Skip to main content
15,885,278 members
Please Sign up or sign in to vote.
2.17/5 (3 votes)
See more:
How to Make a folder(directory) compressed (RAR) file without using third party dlls.
Posted
Comments
Zoltán Zörgő 28-Dec-12 4:22am    
Define "third party" in your situation!

Rar format and algorithm is proprietary. But you can have unrar code for free (http://www.rarlab.com/rar_add.htm[^]), so you might take you chance to get an idea.

Why do you stick to rar, there are other other formats, where you can make your own implementation without restriction.
But after all, why bothering with implementing something that you already have?

Just a note: compression algorithms are really complicated. Here you can read about the probably simplest after RLE: the Huffman code[^]
 
Share this answer
 
v2
Well obviously you need to iterate through all files in your directory and copress those files with GZipStream..
 
Share this answer
 
How can we add password protection in this
 
Share this answer
 
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:\Documents and Settings\My Documents\Visual Studio 2008\Projects\ConsoleApplication1\bin\Debug\Stuff\text1.txt";
            string sZipFile = @"C:\Documents and Settings\My Documents\Visual Studio 2008\Projects\ConsoleApplication1\bin\Debug\Stuff\text1.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
 
v2
Comments
Emre Ataseven 20-Apr-14 14:01pm    
Is it rar?

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