C# 实现 压缩 && 解压缩

        static void Main(string[] args)
        {
            //string fileToZipPath = "Ionic.Zip.xml";
            //string zipedFileName = "CitiGroup.zip";
            //Zip(fileToZipPath,zipedFileName);

            string unZipedFileName = "CitiGroup.zip";
            string extractFilePath = @"E:\CitiGroup";
            UnZip(extractFilePath, unZipedFileName);
        }

        /// <summary>
        /// 压缩 Zip
        /// </summary>
        /// <param name="fileToZips">文件路径集合</param>
        /// <param name="zipedFile">想要压成zip的文件名</param>
        public static void Zip(string fileToZip, string zipedFile)
        {
            using (Ionic.Zip.ZipFile zip = new Ionic.Zip.ZipFile(zipedFile, Encoding.Default))
            {
                using (FileStream fs = new FileStream(fileToZip, FileMode.Open, FileAccess.ReadWrite))
                {
                    byte[] buffer = new byte[fs.Length];
                    fs.Read(buffer, 0, buffer.Length);
                    string fileName = fileToZip.Substring(fileToZip.LastIndexOf("\\") + 1);
                    zip.AddEntry(fileName, buffer);
                }
                zip.Save();
            }
        }

        /// <summary>
        /// 解压缩 Zip
        /// </summary>
        public static void UnZip(string extractFilePath,string unzipFile)
        {
            using (Ionic.Zip.ZipFile zip = Ionic.Zip.ZipFile.Read(unzipFile))
            {
                foreach (Ionic.Zip.ZipEntry z in zip)
                {
                    z.Extract(extractFilePath);
                }
            } 
        }

 

 

C#教程:把Excel文件转换成CSV格式

http://ju.outofmemory.cn/entry/34445

C#读取Excel和CSV为DataTable

http://blog.csdn.net/wjbaiverson/article/details/6226156

C# Winform Excel和CSV互转

http://www.cnblogs.com/junjie94wan/archive/2013/05/23/3094483.html

 

 

 

posted on 2013-05-06 16:45  JackSlaterYu  阅读(340)  评论(0编辑  收藏  举报