Extracting and Compressing Files

Extracting/Compressing Files. This snippet is all about compressing some group of files and extracting the same. It is achieved using the class GZipStream which is available using the namespace System.IO.Compression;

In .NET 2.0 you compress your files.

Namespace you have to use is System.IO.Compression;

FileStream fsOpen = new FileStream("Sample_Text_File.doc", FileMode.Open);
byte[] inputFile = new byte[fsOpen.Length];
fsOpen.Read(inputFile, 0, inputFile.Length);

FileStream fsZip = new FileStream("Sample_Text_File.gzip",
GZipStream zipFile = new GZipStream(zipFile, CompressionMode.Compress);

zipFile.Write(input, 0, input.Length);

In .NET 2.0 GzipStream is a object which is used to Zip a file using the namespace System.IO.Compression

For Extracting the Compressed file who need to do the same mentioned above whereas Instead of CompressionMode.Compress in the object you have created for GZipStream, you have to mention as CompressionMode.Decompress which extract the files which is in the .gzip format

Prakash Alamanda


No responses found. Be the first to comment...

  • Do not include your name, "with regards" etc in the comment. Write detailed comment, relevant to the topic.
  • No HTML formatting and links to other web sites are allowed.
  • This is a strictly moderated site. Absolutely no spam allowed.
  • Name: