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

推荐订阅源

cs.CV updates on arXiv.org
cs.CV updates on arXiv.org
小众软件
小众软件
博客园_首页
博客园 - 聂微东
V
V2EX
WordPress大学
WordPress大学
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
罗磊的独立博客
酷 壳 – CoolShell
酷 壳 – CoolShell
博客园 - 司徒正美
博客园 - 三生石上(FineUI控件)
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
S
SegmentFault 最新的问题
J
Java Code Geeks
Last Week in AI
Last Week in AI
The Cloudflare Blog
月光博客
月光博客
雷峰网
雷峰网
宝玉的分享
宝玉的分享
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
Hugging Face - Blog
Hugging Face - Blog
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
有赞技术团队
有赞技术团队
人人都是产品经理
人人都是产品经理
博客园 - Franky
腾讯CDC
Jina AI
Jina AI
博客园 - 叶小钗
大猫的无限游戏
大猫的无限游戏
阮一峰的网络日志
阮一峰的网络日志
量子位
爱范儿
爱范儿
美团技术团队
T
Tailwind CSS Blog
博客园 - 【当耐特】
D
Docker
IT之家
IT之家
V
Visual Studio Blog
P
Proofpoint News Feed
L
LangChain Blog
Engineering at Meta
Engineering at Meta
C
Check Point Blog
G
Google Developers Blog
Google DeepMind News
Google DeepMind News
云风的 BLOG
云风的 BLOG
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
Microsoft Azure Blog
Microsoft Azure Blog
B
Blog RSS Feed
Recorded Future
Recorded Future

博客园 - 邢帅杰

CSRedisCore用法 Android 常用数据目录(内部 / 外部、缓存、文件) 的 获取方法对照表 安卓把assets中的文件copy到app目录中 oracle执行sql语句前清除缓存 安卓开发使用interface自定义回调函数 安装DockerDesktop并启用 oracle中decode用法 vue使用import.meta编译报错,import.meta.env报:类型“ImportMeta”上不存在属性“env”。必须配置module。 oracle游标使用详解 oracle存储过程中声明一个行变量,接收游标中的行数据。variable_name table_name%ROWTYPE oracle NVL和NVL2 C#获取文件md5码 oracle查询存储过程和函数中是否包含某个字符串 Android清除WebView缓存 C#获取当前日期是星期几 切换项目git地址,项目迁移到新git地址 C#线程同步、跨进程同步Mutex详解、C#只允许运行一个实例 Android Stack说明 安卓打开第三方app并传入参数 安卓如何唤醒深度睡眠的设备并执行任务 java两个日期相差秒数
.net core使用SharpZipLib压缩zip文件并设置密码
邢帅杰 · 2026-05-28 · via 博客园 - 邢帅杰

nuget安装SharpZipLib

/// <summary>
/// 压缩zip并设置密码
/// </summary>
/// <param name="sourceDir">要压缩的目录</param>
/// <param name="zipFile">压缩后zip存放地址</param>
/// <param name="password">密码</param>
public static void CreateZipPwd(string sourceDir, string zipFile, string password)
{
    if (File.Exists(zipFile)) File.Delete(zipFile);

    using (FileStream fs = new FileStream(zipFile, FileMode.Create))
    using (ZipOutputStream zipOut = new ZipOutputStream(fs))
    {
        zipOut.Password = password;
        zipOut.UseZip64 = UseZip64.On;
        zipOut.SetLevel(Deflater.DEFAULT_COMPRESSION);

        AddDirectoryToZip(zipOut, sourceDir, sourceDir);
    }
}
private static void AddDirectoryToZip(ZipOutputStream zipOut, string currentDir, string rootDir)
{
    foreach (string file in Directory.GetFiles(currentDir))
    {
        FileInfo fi = new FileInfo(file);
        string relPath = Path.GetRelativePath(rootDir, file).Replace("\\", "/");

        ZipEntry entry = new ZipEntry(relPath);
        entry.DateTime = fi.LastWriteTime;
        entry.Size = fi.Length;

        zipOut.PutNextEntry(entry);

        using (FileStream fs = fi.OpenRead())
            fs.CopyTo(zipOut);

        zipOut.CloseEntry();
    }

    foreach (string dir in Directory.GetDirectories(currentDir))
        AddDirectoryToZip(zipOut, dir, rootDir);
}

demo

 string sourceDir = "E:\\2026";
 string zipFile = "E:\\2026-01.zip";
 string password = "123456";
 CreateZipPwd(sourceDir, zipFile, password);