惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

H
Hackread – Cybersecurity News, Data Breaches, AI and More
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
V
V2EX
T
The Blog of Author Tim Ferriss
腾讯CDC
Hugging Face - Blog
Hugging Face - Blog
雷峰网
雷峰网
爱范儿
爱范儿
GbyAI
GbyAI
H
Help Net Security
I
InfoQ
罗磊的独立博客
酷 壳 – CoolShell
酷 壳 – CoolShell
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
人人都是产品经理
人人都是产品经理
J
Java Code Geeks
Microsoft Security Blog
Microsoft Security Blog
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
N
Netflix TechBlog - Medium
Last Week in AI
Last Week in AI
宝玉的分享
宝玉的分享
云风的 BLOG
云风的 BLOG
Project Zero
Project Zero
P
Privacy & Cybersecurity Law Blog
A
Arctic Wolf
Know Your Adversary
Know Your Adversary
G
Google Developers Blog
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
T
Tor Project blog
V
Vulnerabilities – Threatpost
Y
Y Combinator Blog
WordPress大学
WordPress大学
V
Visual Studio Blog
博客园_首页
G
GRAHAM CLULEY
K
Kaspersky official blog
T
Tailwind CSS Blog
T
Threat Research - Cisco Blogs
博客园 - Franky
D
Docker
Security Latest
Security Latest
I
Intezer
有赞技术团队
有赞技术团队
Application and Cybersecurity Blog
Application and Cybersecurity Blog
博客园 - 【当耐特】
B
Blog RSS Feed
T
The Exploit Database - CXSecurity.com
cs.CV updates on arXiv.org
cs.CV updates on arXiv.org
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻

博客园 - 子风

Android相关转载帖子 c++ 函数的工作原理 C和C++的存储模式 VS2005配置开发ARM c++ 虚析构函数的思考 arm-linux-g++ 下交叉编译libxml2 (转)Eclipse代码提示功能设置(Java & C/C++) linux下面eclipse的c++配置 VS2008 配置boost 用VS.NET2008打包程序遇到不可恢复的生成错误的解决方案 推荐一个原型的设计软件 Mockups For Desktop Grid++Report——推模式下填充子报表 c# 对象的创建过程 Failure sending mail - 子风 XP下IIS错误:Server Application Error css总结 asp.net缓存-数据依赖缓存 - 子风 - 博客园 .net 测试工具 .net 发送Email
利用7z来分卷压缩文件
子风 · 2010-02-09 · via 博客园 - 子风

最近做一个发送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();
             SevenZipCompressor.SetLibraryPath(Application.StartupPath 
+ "/7z.dll");
             
//tmp.VolumeSize =fInfo.Length <=  this.fileSize ? 0 :this.fileSize;
              tmp.VolumeSize = this.fileSize;//卷的大小,最大只能分离1000个文件
             tmp.ArchiveFormat = OutArchiveFormat.SevenZip;
             tmp.CompressDirectory(descDecPath,copyFilePath );

             File.Delete(copyFilePath);

// 删除Copy的文件

             
if (Directory.GetFiles(descDecPath).Length == 1)
             {
                 
foreach (string path in Directory.GetFiles(descDecPath))
                 {
                     File.Delete(path);
                 }
                 tmp.VolumeSize 
= 0;
                 tmp.CompressFiles(copyFilePath
+".7z" ,
                                   
new string[] { filePath });//压缩文件

             }
             Application.DoEvents();
             
return true;

         }

由于没有文件的分卷压缩的类库,所以我求其次,用文件夹的分卷压缩,先把文件copy到一个临时的文件夹中,然后对这个临时的文件夹进行分卷压缩

见代码:

学习,积累中......