Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: .NET3.0 C#
How to Make a folder(directory) compressed (RAR) file without using third party dlls.
Posted 27-Dec-12 23:03pm
Comments
Zoltán Zörgő at 28-Dec-12 4:22am
   
Define "third party" in your situation!
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

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[^]
  Permalink  
v2
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 5

How can we add password protection in this
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 4

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();
            }
        }
    }
}
  Permalink  
v2
Comments
Emre Ataseven at 20-Apr-14 14:01pm
   
Is it rar?
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

Well obviously you need to iterate through all files in your directory and copress those files with GZipStream..
  Permalink  

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

  Print Answers RSS
0 OriginalGriff 304
1 Sergey Alexandrovich Kryukov 255
2 Shweta N Mishra 216
3 Maciej Los 210
4 PIEBALDconsult 184
0 OriginalGriff 7,630
1 Sergey Alexandrovich Kryukov 7,022
2 DamithSL 5,586
3 Manas Bhardwaj 4,946
4 Maciej Los 4,525


Advertise | Privacy | Mobile
Web03 | 2.8.1411023.1 | Last Updated 18 Apr 2014
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