公交车上荫蒂添的好舒服的电影-公用玩物(np双xing总受)-公用小荡货芊芊-公与妇仑乱hd-攻把受做哭边走边肉楼梯play-古装一级淫片a免费播放口

LOGO OA教程 ERP教程 模切知識交流 PMS教程 CRM教程 開發(fā)文檔 其他文檔  
 
網(wǎng)站管理員

【C#】使用DotNetZip壓縮與解壓縮

admin
2024年1月19日 14:46 本文熱度 1335
DotnetZip是一個開源類庫,支持.NET的任何語言,可很方便的創(chuàng)建,讀取,和更新zip文件。而且還可以使用在.NETCompact Framework中。 

下載地址在這里:附件:DotNetZip.rar

解壓后放到主程序同一個目錄下,引用Ionic.Zip.dll就可以了:

然后引用這個命名空間:

using Ionic.Zip;

以下是使用代碼:

01.using System;
02.using System.Collections.Generic;
03.using System.ComponentModel;
04.using System.Data;
05.using System.Drawing;
06.using System.Linq;
07.using System.Text;
08.using System.Windows.Forms;
09.using Ionic.Zip;
10.namespace WindowsFormsZIP
11.{
12.    public partial class Form1 : Form
13.    {
14.        public Form1()
15.        {
16.            InitializeComponent();
17.        }
18.
19.        /// <summary>
20.        /// 壓縮帶中文的文件名.  
21.        /// </summary>
22.        /// <param name="sender">The source of the event.</param>
23.        /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param>
24.        private void button1_Click(object sender, EventArgs e)
25.        {
26.
27.            using (ZipFile zip = new ZipFile("蘇志.zip",Encoding.Default))
28.            {
29.                zip.AddFile("數(shù)據(jù)庫文檔.doc");
30.                zip.Save();
31.            }
32.
33.        }
34.
35.        /// <summary>
36.        /// 用密碼加密ZIP文件.  
37.        /// </summary>
38.        /// <param name="sender">The source of the event.</param>
39.        /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param>
40.        private void button2_Click(object sender, EventArgs e)
41.        {
42.
43.            using (ZipFile zip = new ZipFile())
44.            {
45.                zip.CompressionLevel = Ionic.Zlib.CompressionLevel.BestCompression;   //設(shè)置壓縮率

45.                zip.Password = "123456!";

46.                zip.AddFile("WPF 4 Unleashed.pdf");

47.                zip.Save("WPF 4 Unleashed.zip");
48.            }
49.
50.        }
51.
52.        /// <summary>
53.        /// 壓縮文件夾  
54.        /// </summary>
55.        /// <param name="sender">The source of the event.</param>
56.        /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param>
57.        private void button3_Click(object sender, EventArgs e)
58.        {
59.            using (ZipFile zip = new ZipFile())
60.            {
61.                zip.AddDirectory(@"E:\suzhi");
62.                zip.Comment = "This zip was created at " + System.DateTime.Now.ToString("G");
63.                zip.Save("test.zip");
64.            }
65.        }
66.
67.        /// <summary>
68.        /// 抽取ZIP中的文件到指定的文件夾.  
69.        /// </summary>
70.        /// <param name="sender">The source of the event.</param>
71.        /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param>
72.        private void button4_Click(object sender, EventArgs e)
73.        {
74.            using (ZipFile zip = ZipFile.Read("test.zip"))
75.            {
76.                foreach (ZipEntry z in zip)
77.                {
78.                    z.Extract(@"F:\kk");
79.                }
80.            }
81.
82.        }
83.
84.    }
85.}

具體的例子:

           //獲取壓縮包路徑
           string filename = material.CreationTime.ToyyyyMMdd().Replace("-""");

           //string zippath = AppDomain.CurrentDomain.BaseDirectory + "upload\\Zipped\\" + filename;
           
//和上面的結(jié)果一樣
           string zippath = material.FilePath;
           string decomPath = "";
           string nowpath = "";
           if (material.FilePath.Substring(material.FilePath.Length - 33).Equals("zip"))
           { decomPath = material.FilePath.Replace(".zip"""); }
           if (material.FilePath.Substring(material.FilePath.Length - 33).Equals("rar"))
           { decomPath = material.FilePath.Replace(".rar"""); }
           //查詢此目錄下是否存在需要解壓過的同名的文件夾名稱
           DirectoryInfo direInfo = new DirectoryInfo(decomPath);
           if (direInfo.Exists)
           {
               DirectoryInfo[] childs = direInfo.GetDirectories();
               foreach (DirectoryInfo child in childs)
               {
                   child.Delete(true);
               }
               direInfo.Delete(true);
           }

           //解壓文件夾
           using (ZipFile zip = ZipFile.Read(zippath))
           {

               foreach (ZipEntry z in zip)
               {
                   //z.Extract(material.FilePath.Replace(".zip", ""));
                   z.Extract(zippath.Replace(".zip"""));
               }
           }

           direInfo = new DirectoryInfo(zippath.Replace(".zip"""));
           if (direInfo.Exists)
           {
               DirectoryInfo[] dirchild = direInfo.GetDirectories();
               if (dirchild.Count() == 1)
               {
                    nowpath = decomPath + "\\" + dirchild[0].Name;
                   direInfo = new DirectoryInfo(nowpath);
                   DirectoryInfo[] dirchild2 = direInfo.GetDirectories();
                   foreach (DirectoryInfo childrens in dirchild2)
                   {

                       //修改文件夾的內(nèi)容
                       FileStream fs = new FileStream(nowpath +"\\"+ childrens.Name + "\\index.html", FileMode.OpenOrCreate, FileAccess.ReadWrite);
                       string fileText = "";
                       GameServer server = GameServerService.GetGameServerWithGame(materialLog.ServerId);
                       Game game = server.Game;
                       using (StreamReader sr = new StreamReader(fs))
                       {
                           fileText = sr.ReadToEnd();
                           fileText = fileText.Replace("#GameCode#", game.Code);
                           fileText = fileText.Replace("#ServerCode#", server.Code);
                           fileText = fileText.Replace("#ServerId#", Convert.ToString(server.ServerId));
                       }
                       if (fileText != "")
                       {
                           using (StreamWriter sw = new StreamWriter(nowpath + "\\" + childrens.Name + "\\index.html"false, Encoding.Default))
                           {
                               sw.Write(fileText);
                           }
                       }

                   }
               }
               
           }

           //重新壓縮

           using (ZipFile zip = new ZipFile())
           {
               zip.AddDirectory(decomPath);
               zip.Save(nowpath+".zip");
           }

該文章在 2024/1/19 22:48:33 編輯過
關(guān)鍵字查詢
相關(guān)文章
正在查詢...
點晴ERP是一款針對中小制造業(yè)的專業(yè)生產(chǎn)管理軟件系統(tǒng),系統(tǒng)成熟度和易用性得到了國內(nèi)大量中小企業(yè)的青睞。
點晴PMS碼頭管理系統(tǒng)主要針對港口碼頭集裝箱與散貨日常運作、調(diào)度、堆場、車隊、財務(wù)費用、相關(guān)報表等業(yè)務(wù)管理,結(jié)合碼頭的業(yè)務(wù)特點,圍繞調(diào)度、堆場作業(yè)而開發(fā)的。集技術(shù)的先進性、管理的有效性于一體,是物流碼頭及其他港口類企業(yè)的高效ERP管理信息系統(tǒng)。
點晴WMS倉儲管理系統(tǒng)提供了貨物產(chǎn)品管理,銷售管理,采購管理,倉儲管理,倉庫管理,保質(zhì)期管理,貨位管理,庫位管理,生產(chǎn)管理,WMS管理系統(tǒng),標簽打印,條形碼,二維碼管理,批號管理軟件。
點晴免費OA是一款軟件和通用服務(wù)都免費,不限功能、不限時間、不限用戶的免費OA協(xié)同辦公管理系統(tǒng)。
Copyright 2010-2025 ClickSun All Rights Reserved

主站蜘蛛池模板: 精品丝袜人妻 | 国产成人午夜福在线观看 | 精品欧洲av无码一区二区14 | 国产综合精品一区二区三区 | a级毛片视频免费观看不卡 a级毛片视频在线观看 | 高潮添下面视频免费看 | a级片久久影 | 成人欧美一区二区三区在线观看 | 国产制服日本一区二区 | 精品无码av一区 | 国产精品影片在线观看 | 国产专区免费av无码 | 国产一区二区无码蜜芽精品 | 国产精品一卡 | 白洁一区二区三区中文 | 国产一区二区视频在线 | av片在线观看不卡 | 国自产精品手机在线视拍 | 国产白丝 | 动漫精品中文字幕无码第一页 | 精品国产人成亚洲区 | 国产精品午夜福利麻豆 | 91蜜桃视| 成人精品一区二区久久久 | 国产成人免费高清 | 国产午夜福利片 | 国产精品盗摄一区二区在线 | aⅴ无码一级a片在线视频免费 | 加勒比精品久久一区二区三区 | 精品亚洲欧美日韩久久 | av在线免费不卡可看 | 2025无码最新国产在线观看 | 国产午夜福利在线播放 | 成人碰碰视频公开老师 | 东京热av加勒比一区二区 | 国产免费人成视频在线观看 | 国产白丝喷水娇喘视 | 粉嫩av久久一区二区三区王玥 | 国产精品高潮呻吟久久av | 国产日韩精品在线播放 | 97无码精品人妻一区二区三区 |