|
using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.IO;
using java.util;
using java.util.zip;
using java.io;
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void lnkImage_Click(object sender, EventArgs e)
{
string FilePath = Server.MapPath("~/Image/");
string FileDest = Server.MapPath("~/Image/");
Zip(FileDest + "test.zip", FilePath + "pic.jpg");
}
private void Zip(string zipFileName, string sourceFile)
{
FileOutputStream filOpStrm = new FileOutputStream(zipFileName);
ZipOutputStream zipOpStrm = new ZipOutputStream(filOpStrm);
FileInputStream filIpStrm = null;
filIpStrm = new FileInputStream(sourceFile);
ZipEntry ze = new ZipEntry(Path.GetFileName(sourceFile));
zipOpStrm.putNextEntry(ze);
sbyte[] buffer = new sbyte[1024];
int len = 0;
while ((len = filIpStrm.read(buffer)) >= 0)
{
zipOpStrm.write(buffer, 0, len);
}
zipOpStrm.closeEntry();
filIpStrm.close();
zipOpStrm.close();
filOpStrm.close();
FileInfo file = new FileInfo(zipFileName);
Response.ClearHeaders();
Response.ClearContent();
Response.ContentType = "application/octet-stream";
Response.AddHeader("Content-Disposition", "attachment; filename=" + "test.zip");
Response.WriteFile(file.FullName);
Response.End();
}
}
|
By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.
If a file you wish to view isn't highlighted, and is a text file (not binary), please
let us know and we'll add colourisation support for it.
I am Souvik Das, Microsoft Certified Professional, ITIL, M.C.A post graduate having over 7 years of experience as a Sr. Software Developer. I'm currently working as a Sr. Software Developer from OHI Group.