自定义博客皮肤VIP专享

*博客头图:

格式为PNG、JPG,宽度*高度大于1920*100像素,不超过2MB,主视觉建议放在右侧,请参照线上博客头图

请上传大于1920*100像素的图片!

博客底图:

图片格式为PNG、JPG,不超过1MB,可上下左右平铺至整个背景

栏目图:

图片格式为PNG、JPG,图片宽度*高度为300*38像素,不超过0.5MB

主标题颜色:

RGB颜色,例如:#AFAFAF

Hover:

RGB颜色,例如:#AFAFAF

副标题颜色:

RGB颜色,例如:#AFAFAF

自定义博客皮肤

-+
  • 博客(0)
  • 资源 (4)
  • 收藏
  • 关注

空空如也

NGUI 3.5.6

NGUI 3.5.6包含离线文档 NGUI 3.5.6包含离线文档

2014-04-16

NGUI Next-Gen UI 3.5.3

NGUI Next-Gen UI 3.5.3

2014-04-10

SharpZipLib.dll

c#压缩解压 文件夹 需要在项目里引用SharpZipLib.dll 1using System; 2using System.Collections.Generic; 3using System.Text; 4using System.IO; 5using ICSharpCode.SharpZipLib; 6using ICSharpCode.SharpZipLib.Zip; 7using ICSharpCode.SharpZipLib.Checksums; 8 9/**//* 10 * 解压缩 11 * 该程序压缩和解压配合才能使用 12 * 普通用 Winrar 压缩的文件该解压不能通过 13 * Modify By HJ 2007-10-25 14 */ 15namespace ZipApplication 16{ 17 /**//// <summary> 18 /// 压缩类 19 /// </summary> 20 public class ZipClass 21 { 22 /**//// <summary> 23 /// 递归压缩文件夹方法 24 /// </summary> 25 /// <param name="FolderToZip"></param> 26 /// <param name="s"></param> 27 /// <param name="ParentFolderName"></param> 28 private static bool ZipFileDictory(string FolderToZip, ZipOutputStream s, string ParentFolderName) 29 { 30 bool res = true; 31 string[] folders, filenames; 32 ZipEntry entry = null; 33 FileStream fs = null; 34 Crc32 crc = new Crc32(); 35 36 try 37 { 38 39 //创建当前文件夹 40 entry = new ZipEntry(Path.Combine(ParentFolderName, Path.GetFileName(FolderToZip) + "/")); //加上 “/” 才会当成是文件夹创建 41 s.PutNextEntry(entry); 42 s.Flush(); 43 44 45 //先压缩文件,再递归压缩文件夹 46 filenames = Directory.GetFiles(FolderToZip); 47 foreach (string file in filenames) 48 { 49 //打开压缩文件 50 fs = File.OpenRead(file); 51 52 byte[] buffer = new byte[fs.Length]; 53 fs.Read(buffer, 0, buffer.Length); 54 entry = new ZipEntry(Path.Combine(ParentFolderName, Path.GetFileName(FolderToZip) + "/" + Path.GetFileName(file))); 55 56 entry.DateTime = DateTime.Now; 57 entry.Size = fs.Length; 58 fs.Close(); 59 60 crc.Reset(); 61 crc.Update(buffer); 62 63 entry.Crc = crc.Value; 64 65 s.PutNextEntry(entry); 66 67 s.Write(buffer, 0, buffer.Length); 68 } 69 } 70 catch 71 { 72 res = false; 73 } 74 finally 75 { 76 if (fs != null) 77 { 78 fs.Close(); 79 fs = null; 80 } 81 if (entry != null) 82 { 83 entry = null; 84 } 85 GC.Collect(); 86 GC.Collect(1); 87 } 88 89 90 folders = Directory.GetDirectories(FolderToZip); 91 foreach (string folder in folders) 92 { 93 if (!ZipFileDictory(folder, s, Path.Combine(ParentFolderName, Path.GetFileName(FolderToZip)))) 94 { 95 return false; 96 } 97 } 98 99 return res; 100 } 101 102 /**//// <summary> 103 /// 压缩目录 104 /// </summary> 105 /// <param name="FolderToZip">待压缩的文件夹,全路径格式</param> 106 /// <param name="ZipedFile">压缩后的文件名,全路径格式</param> 107 /// <returns></returns> 108 private static bool ZipFileDictory(string FolderToZip, string ZipedFile, String Password) 109 { 110 bool res; 111 if (!Directory.Exists(FolderToZip)) 112 { 113 return false; 114 } 115 116 ZipOutputStream s = new ZipOutputStream(File.Create(ZipedFile)); 117 s.SetLevel(6); 118 s.Password = Password; 119 120 res = ZipFileDictory(FolderToZip, s, ""); 121 122 s.Finish(); 123 s.Close(); 124 125 return res; 126 } 127 128 /**//// <summary> 129 /// 压缩文件 130 /// </summary> 131 /// <param name="FileToZip">要进行压缩的文件名</param> 132 /// <param name="ZipedFile">压缩后生成的压缩文件名</param> 133 /// <returns></returns> 134 private static bool ZipFile(string FileToZip, string ZipedFile, String Password) 135 { 136 //如果文件没有找到,则报错 137 if (!File.Exists(FileToZip)) 138 { 139 throw new System.IO.FileNotFoundException("指定要压缩的文件: " + FileToZip + " 不存在!"); 140 } 141 //FileStream fs = null; 142 FileStream ZipFile = null; 143 ZipOutputStream ZipStream = null; 144 ZipEntry ZipEntry = null; 145 146 bool res = true; 147 try 148 { 149 ZipFile = File.OpenRead(FileToZip); 150 byte[] buffer = new byte[ZipFile.Length]; 151 ZipFile.Read(buffer, 0, buffer.Length); 152 ZipFile.Close(); 153 154 ZipFile = File.Create(ZipedFile); 155 ZipStream = new ZipOutputStream(ZipFile); 156 ZipStream.Password = Password; 157 ZipEntry = new ZipEntry(Path.GetFileName(FileToZip)); 158 ZipStream.PutNextEntry(ZipEntry); 159 ZipStream.SetLevel(6); 160 161 ZipStream.Write(buffer, 0, buffer.Length); 162 } 163 catch 164 { 165 res = false; 166 } 167 finally 168 { 169 if (ZipEntry != null) 170 { 171 ZipEntry = null; 172 } 173 if (ZipStream != null) 174 { 175 ZipStream.Finish(); 176 ZipStream.Close(); 177 } 178 if (ZipFile != null) 179 { 180 ZipFile.Close(); 181 ZipFile = null; 182 } 183 GC.Collect(); 184 GC.Collect(1); 185 } 186 187 return res; 188 } 189 190 /**//// <summary> 191 /// 压缩文件 和 文件夹 192 /// </summary> 193 /// <param name="FileToZip">待压缩的文件或文件夹,全路径格式</param> 194 /// <param name="ZipedFile">压缩后生成的压缩文件名,全路径格式</param> 195 /// <returns></returns> 196 public static bool Zip(String FileToZip, String ZipedFile, String Password) 197 { 198 if (Directory.Exists(FileToZip)) 199 { 200 return ZipFileDictory(FileToZip, ZipedFile, Password); 201 } 202 else if (File.Exists(FileToZip)) 203 { 204 return ZipFile(FileToZip, ZipedFile, Password); 205 } 206 else 207 { 208 return false; 209 } 210 } 211 } 212 /// <summary> /// 解压类 /// </summary> public class UnZipClass { /**//// <summary> /// 解压功能(解压压缩文件到指定目录) /// </summary> /// <param name="FileToUpZip">待解压的文件</param> /// <param name="ZipedFolder">指定解压目标目录</param> public static void UnZip(string FileToUpZip, string ZipedFolder,string Password) { if (!File.Exists(FileToUpZip)) { return; } if (!Directory.Exists(ZipedFolder)) { Directory.CreateDirectory(ZipedFolder); } ZipInputStream s = null; ZipEntry theEntry = null; string fileName; FileStream streamWriter = null; try { s = new ZipInputStream(File.OpenRead(FileToUpZip)); s.Password = Password; while ((theEntry = s.GetNextEntry()) != null) { if (theEntry.Name != String.Empty) { fileName = Path.Combine(ZipedFolder, theEntry.Name); /**////判断文件路径是否是文件夹 if (fileName.EndsWith("/") || fileName.EndsWith("\\")) { Directory.CreateDirectory(fileName); continue; } streamWriter = File.Create(fileName); int size = 2048; byte[] data = new byte[2048]; while (true) { size = s.Read(data, 0, data.Length); if (size > 0) { streamWriter.Write(data, 0, size); } else { break; } } } } } finally { if (streamWriter != null) { streamWriter.Close(); streamWriter = null; } if (theEntry != null) { theEntry = null; } if (s != null) { s.Close(); s = null; } GC.Collect(); GC.Collect(1); } } } } 本文来自CSDN博客,转载请标明出处:http://blog.csdn.net/kevin_cheung/archive/2008/12/04/3442164.aspx

2010-04-29

空空如也

TA创建的收藏夹 TA关注的收藏夹

TA关注的人

提示
确定要删除当前文章?
取消 删除