电脑桌面
添加蚂蚁七词文库到电脑桌面
安装后可以在桌面快捷访问

二开文件压缩

来源:金蝶云社区作者:金蝶2024-09-165

二开文件压缩

using ICSharpCode.SharpZipLib.Checksums;

using ICSharpCode.SharpZipLib.Zip;

using System;

using System.Collections.Generic;

using System.IO;

using System.Linq;

using System.Text;


namespace WLQDDR.BusinessPlugIn

{

  public  class ZipHelper

    {

        /// <summary>

        /// ZIP:压缩文件夹

        /// add yuangang by 2016-06-13

        /// </summary>

        /// <param name="DirectoryToZip">需要压缩的文件夹(绝对路径)</param>

        /// <param name="ZipedPath">压缩后的文件路径(绝对路径)</param>

        /// <param name="ZipedFileName">压缩后的文件名称(文件名,默认 同源文件夹同名)</param>

        /// <param name="IsEncrypt">是否加密(默认 加密)</param>

        public static void ZipDirectory(string DirectoryToZip, string ZipedPath, string ZipedFileName = "", bool IsEncrypt = true)

        {

            //如果目录不存在,则报错

            if (!System.IO.Directory.Exists(DirectoryToZip))

            {

                throw new System.IO.FileNotFoundException("指定的目录: " + DirectoryToZip + " 不存在!");

            }


            //文件名称(默认同源文件名称相同)

            string ZipFileName = string.IsNullOrEmpty(ZipedFileName) ? ZipedPath + "\\" + new DirectoryInfo(DirectoryToZip).Name + ".zip" : ZipedPath + "\\" + ZipedFileName + ".zip";


            using (System.IO.FileStream ZipFile = System.IO.File.Create(ZipFileName))

            {

                using (ZipOutputStream s = new ZipOutputStream(ZipFile))

                {

                    if (IsEncrypt)

                    {

                        //压缩文件加密

                        s.Password = "123";

                    }

                    ZipSetp(DirectoryToZip, s, "");

                }

            }

        }

        /// <summary>

        /// 递归遍历目录

        /// add yuangang by 2016-06-13

        /// </summary>

        private static void ZipSetp(string strDirectory, ZipOutputStream s, string parentPath)

        {

            if (strDirectory[strDirectory.Length - 1] != Path.DirectorySeparatorChar)

            {

                strDirectory += Path.DirectorySeparatorChar;

            }

            Crc32 crc = new Crc32();


            string[] f

二开文件压缩

using ICSharpCode.SharpZipLib.Checksums;using ICSharpCode.SharpZipLib.Zip;using System;using System.Collections.Generic;using...
点击下载文档文档为doc格式

声明:除非特别标注,否则均为本站原创文章,转载时请以链接形式注明文章出处。如若本站内容侵犯了原著者的合法权益,可联系本站删除。

已经是第一篇
确认删除?
回到顶部
客服QQ
  • 客服QQ点击这里给我发消息
QQ群
  • 答案:my7c点击这里加入QQ群
支持邮箱
微信
  • 微信