話不多說,直接上**,最後有重要說明!!!哦對了,用的是icsharpcode.sharpziplib.zip; 這個東西
壓縮:先宣告個全域性變數吧:
下面就是壓縮的**了://附件打包的變數
zipoutputstream zos = null;
protected void btnfile_click(object sender, eventargs e)
protected void dlzipdir()
protected void addzipentry()}}
}/// /// 獲取所有附件的datatable1
///
///
private datatable getaccessory()
還有md5加密的方法
#region "md5加密"
/// ///32位 md5加密
///
/// 加密字元
///
public static string encrypt(string str)
return pwd;
}#endregion
下面是解壓縮的「
/// /// 解壓縮檔案
///
/// 壓縮包檔名
/// 解壓縮目標路徑
public static void decompress(string gzipfile, string targetpath)
string currentdirectory = directoryname;
byte data = new byte[2048];
int size = 2048;
zipentry theentry = null;
using (zipinputstream s = new zipinputstream(file.openread(gzipfile)))
else
}//解壓檔案到指定的目錄
using (filestream streamwriter = file.create(currentdirectory + "\\" + theentry.name))
streamwriter.close();}}
}}
s.close();
}}
最後的說明就是:這個壓縮方法是將檔案流到記憶體中,如果檔案過大 有可能造成程式崩掉,反正我是崩掉了。。。
關於壓縮和解壓縮
從http www.icsharpcode.net 首先需要在專案裡引用sharpziplib.dll。然後修改其中的關於壓縮和解壓縮的類。實現原始碼如下 壓縮檔案 using system using system.io using icsharpcode.sharpziplib.checksum...
壓縮和解壓縮OLEVARIANT
uses zlibex procedure varianttostream const v olevariant stream tstream varp pointer begin stream.position 0 stream.size vararrayhighbound v,1 vararra...
ZipArchive壓縮和解壓縮
利用 cocopods 新增第三方類庫 ziparchive 壓縮 1.根據檔案管理器建立壓縮物件zip nsfilemanager manager nsfilemanager defaultmanager ziparchive zip ziparchive alloc initwithfilema...