首页 新闻 搜索 专区 学院

用SharpZipLib進行壓縮時如何加密?

0
[已关闭问题] 关闭于 2007-12-14 08:16
<P><STRONG>請問,各位大蝦:</STRONG></P> <P><STRONG>用SharpZipLib進行壓縮時如何加密?</STRONG></P>
问题补充: 我已經有了答案: #region 壓縮文件 /// <summary> /// 壓縮文件 /// </summary> /// <param name="folderPath">文件夾(絕對路徑)</param> /// <param name="fileName">壓縮的名稱(絕對路徑)</param> public static void ZipFile(string folderPath, string fileName) { ZipFile(folderPath,fileName,null); } /// <summary> /// 壓縮文件 /// </summary> /// <param name="folderPath">文件夾(絕對路徑)</param> /// <param name="fileName">壓縮的名稱(絕對路徑)</param> /// <param name="password"></param> public static void ZipFile(string folderPath, string fileName, string password) { string path = folderPath; path = folderPath.TrimEnd('\\'); DirectoryInfo mainDir = new DirectoryInfo(folderPath); FileSystemInfo[] items = mainDir.GetFileSystemInfos(); ZipOutputStream outStream = null; try { outStream = new ZipOutputStream(File.Create(fileName)); if (password != "" && password != null) { outStream.Password = password;//加密 } foreach (FileSystemInfo item in items) { AddZipEntry(ShortDir(item.FullName, path), outStream, out outStream, path); } } catch (Exception e) { throw e; } finally { if (outStream != null) { outStream.CloseEntry(); outStream.Finish(); // 結束壓縮 outStream.Close(); } } } /// <summary> /// 將絕對路徑轉化為相對路徑 /// </summary> /// <param name="s"></param> /// <param name="replace"></param> /// <returns></returns> private static string ShortDir(string s,string replace) { string d = s.Replace((replace + "\\"), ""); return d; } /// <summary> /// 添加壓縮項目 /// </summary> /// <param name="p">p 為需要壓縮的文件夾或文件</param> /// <param name="
陳龑的主页 陳龑 | 菜鸟二级 | 园豆:215
提问于:2007-12-12 15:48
< >
分享
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册