






















最近做一个发送Email的小工具,里面有个附件的功能,
如果附件太大了,一般都是用winara 分卷压缩的,然后在上传。
如何用程序来实现自动的分卷压缩的呢?因为RAR不是免费的,就上网找了7z
安装好7z,把7z.dll拷贝到程式的目录下,引用SevenZipSharp这个DLL
引进 using SevenZip.Sdk.Compression;
using SevenZip; 这两个命名空间
代码
/// <summary>
/// 切割文件,当文件的大小大于配置文件的容量中,就切割文件
/// </summary>
/// <param name="filePath"> User下PDF文件的路径eg User/2000/01/01/xxxx.pdf</param>
/// <param name="descDecPath">User/2000/01/01/temp</param>
/// <returns></returns>
public bool SplitFile(string filePath,string descDecPath)
{
FileInfo fInfo = new FileInfo(filePath);
string copyFilePath = Path.Combine(descDecPath, fInfo.Name);
//if (fInfo.Length <= this.fileSize) return false;
if (!Directory.Exists(descDecPath))
{
Directory.CreateDirectory(descDecPath);
}
File.Copy(filePath, copyFilePath);
Application.DoEvents();
SevenZipCompressor tmp
= new SevenZipCompressor();File.Delete(copyFilePath);
// 删除Copy的文件}
由于没有文件的分卷压缩的类库,所以我求其次,用文件夹的分卷压缩,先把文件copy到一个临时的文件夹中,然后对这个临时的文件夹进行分卷压缩
见代码:
学习,积累中......
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。