Compress DataTable - CSharp System.IO.Compression

CSharp examples for System.IO.Compression:GZip

Description

Compress DataTable

Demo Code


using System.Runtime.Serialization;
using System.Runtime.Serialization.Formatters.Binary;
using System.IO.Compression;
using System.IO;// w  w  w  . j  a  v a 2s. c o  m
using System.Data;
using System;

public class Main{
        public static byte[] Compress(DataTable dt)
        {
            byte[] buffer = ObjectToByteArray(dt);
            MemoryStream stream = new MemoryStream();
            GZipStream stream2 = new GZipStream(stream, CompressionMode.Compress, true);
            stream2.Write(buffer, 0, buffer.Length);
            stream2.Close();
            stream2.Dispose();
            byte[] buffer2 = stream.ToArray();
            stream.Close();
            stream.Dispose();
            return buffer2;
        }
}

Related Tutorials