Saturday, July 6, 2013

compress file in .rar in C# .net

I have created an application which compress & convert a file in .rar or .zip format.But it can't be open and give error that the file is damaged!!!

string filetocompress = txtSourceFilePath.Text.Substring(txtSourceFilePath.Text.LastIndexOf("\\")+1);
MessageBox.Show(filetocompress);
FileStream sourcefile = File.Create(txtSourceFilePath.Text);
FileStream destination = File.Create(txtTargetFilePath.Text + filetocompress + ".gz");

byte[] buffer = new byte[sourcefile.Length];
sourcefile.Read(buffer, 0, buffer.Length);

using (GZipStream output = new GZipStream(destination, CompressionMode.Compress))
{
Console.WriteLine("Compressing {0} to {1}.", sourcefile.Name, destination.Name, false);

output.Write(buffer, 0, buffer.Length);
}
sourcefile.Close();
destination.Close();
- Full Post

No comments:

Post a Comment