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);
                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);
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, learning, and sharing knowledge.