博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
文件或者文件夹压缩辅助类ZipUtility
阅读量:4293 次
发布时间:2019-05-27

本文共 1671 字,大约阅读时间需要 5 分钟。

程序员老郭 2017-09-26 13:17

文件或者文件夹压缩辅助类ZipUtility

文件或者文件夹压缩辅助类ZipUtility

实现效果

  1. 本辅助类主要是用来方便实现文件(包括文件夹)压缩的辅助操作。

  2. 本类库使用了第三方开源控件ICSharpCode.SharpZipLib。

实现步骤

  1. 在代码引用相关的代码实现动态调用。

  2. 引用ICSharpCode.SharpZipLib.dll类库。

实现代码

1、辅助类提供的方法代码如下所示:

/// <summary>

/// 压缩文件中的文件,可设置密码

/// </summary>

public static void ZipFiles(string inputFolderPath, string outputPathAndFile, string password)

/// <summary>

/// 解压文件到指定的目录,可设置密码、删除原文件等

/// </summary>

public static void UnZipFiles(string zipPathAndFile, string outputFolder, string password, bool deleteZipFile)

/// <summary>

/// 压缩文件

/// </summary>

public static bool ZipFile(string fileToZip, string zipedFile)

/// <summary>

/// 解压缩以后的文件名和路径,压缩前的路径

/// </summary>

public static Boolean UnZipFile(string zipFile, string targetDirectory)

2、辅助类的使用例子代码如下所示

if (manifest != null)

{

string path = Path.GetFullPath(manifest.MyApplication.Location);

foreach (ManifestFile file in manifest.ManifestFiles.Files)

{

bool unzip = false;

bool.TryParse(file.Unzip, out unzip);

if (file.Source.EndsWith(".zip", StringComparison.OrdinalIgnoreCase) && unzip)

{

string zipFile = Path.Combine(path, file.Source);

try

{

ZipUtility.UnZipFiles(zipFile, path, null, true);

}

catch (Exception ex)

{

WriteLine(ex.ToString());

}

}

}

}

/// <summary>

/// 编辑状态下的数据保存

/// </summary>

/// <returns></returns>

public override bool SaveUpdated()

{

bool exist = false;

new ItemDetailServiceClient().Using(client =>

{

exist = client.CheckExist(this.txtItemNo.Text, ID);

});

if (exist)

{

MessageUtil.ShowTips("指定的备件编号已经存在,不能重复添加,请修改");

return false;

}

ItemDetailInfo info = null;

new ItemDetailServiceClient().Using(client =>

{

info = client.FindByID(ID);

});

写在最后

请关注程序员老郭,在菜单 老郭说->我的简书-->获取 ZipUtility 完整代码。

转载地址:http://kyzws.baihongyu.com/

你可能感兴趣的文章
CTA策略05_AtrRsiStrategy
查看>>
CTA策略06_BollChannelStrategy
查看>>
CTA策略07_MultiTimeframeStrategy
查看>>
Ubuntu 14.04安装和卸载搜狗拼音输入法
查看>>
ubuntu 18.04 设置中文输入法
查看>>
ubuntu使用之-rime
查看>>
Ubuntu 18.04/18.10快速开启Google BBR的方法
查看>>
Ubuntu 16.04启用 TCP 拥塞控制之 BBR
查看>>
TCP BBR算法加速效果实测(比对)
查看>>
解决方案大全ImportError: libta_lib.so.0: cannot open shared object file: No such file or directory
查看>>
anaconda报错 ImportError: No module named conda.cli
查看>>
vnpy策略回测如何设置滑点手续费和size
查看>>
virmach主机购买和使用
查看>>
Ubuntu开启Mongodb 外网访问
查看>>
海龟交易法则11_历史测试的谎言
查看>>
海龟交易法则12_脚踏实地地测试
查看>>
海龟交易法则13_系统
查看>>
jq使用教程09_ 教程集合帖-伙伴们贡献,不断更新(4.17)
查看>>
jq使用教程01_最贴心教程,安装JQData全靠这篇指南
查看>>
jq使用教程02_安装的问题
查看>>