0

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();
2
Contributors
1
Reply
20
Views
4 Years
Discussion Span
Last Post by shadyreal
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.