7-12-2009 15:33:34
[code]
string zipFileName = Server.MapPath("/sample.zip");
string sourceFile = Server.MapPath("/code.txt");
string zipname = "zip\\code.txt";
java.io.FileOutputStream fos = new java.io.FileOutputStream(zipFileName);
// Tie to zip stream
java.util.zip.ZipOutputStream zos = new java.util.zip.ZipOutputStream(fos);
// Stream with source file
java.io.FileInputStream fis = new java.io.FileInputStream(sourceFile);
// It's our entry in zip
java.util.zip.ZipEntry ze = new java.util.zip.ZipEntry(zipname);
zos.putNextEntry(ze);
sbyte[] buffer = new sbyte[1024];
int len;
// Read and write until done
while ((len = fis.read(buffer)) >= 0)
{
zos.write(buffer, 0, len);
}
// Close everything
zos.closeEntry();
fis.close();
zos.close();
[/code]
Chú ý để dùng thư viện vjslib.dll
http://www.codeproject.com/KB/cs/vmeasyzipunzip.aspx