ICSharpCode.SharpZipLib.dll 压缩多文件

网站:http://icsharpcode.github.io/SharpZipLib/

引用:ICSharpCode.SharpZipLib.dll

 

private string CompassZipFile(StringList sl,string periodName) {
            string zipPath = AppDomain.CurrentDomain.BaseDirectory + ConfigurationManager.AppSettings["ExportExcelDir"];
            string zipName = periodName + ".zip";
            string zipFile = Path.Combine(zipPath, zipName);

            if (File.Exists(@zipFile))
                File.Delete(@zipFile);
            using (ZipFile zip = ZipFile.Create(@zipFile))
            {
                zip.BeginUpdate();
                zip.SetComment(periodName + "压缩包");
                foreach (string p in sl) {
                    //ZipEntry entry = new ZipEntry(file.Replace(Path.GetPathRoot(file), ""));
                    zip.Add(@p,p.Replace(zipPath.Replace("/","\\"),""));
                }
                zip.CommitUpdate();
            }
            return Path.Combine(ConfigurationManager.AppSettings["ExportExcelDir"], zipName);
        }

 

posted @ 2017-04-21 20:12  三瑞  阅读(363)  评论(0编辑  收藏  举报