Download File to ZIP Sample (Ionic.Zip)

References : Ionic.Zip
Contoh penggunaan :
Dalam kasus ini, file yang akan yang akan di download berupa excel yang telah di convert ke dalam bentuk pdf yang ditampung dalam variable TempData[] dengan key yang diloop.

Catatan :
a. TempData => TempDataDictionary
b. Key => constanta

public ActionResult Download()
{
	var outputStream = new MemoryStream();
	using (var zip = new ZipFile())
	{
		for (int x = 0; x < TempData.Keys.Count(); x++)
		{
			DownloadParameterStub param = TempData[KEY + x] as DownloadParameterStub;
			zip.AddEntry(param.FileName, param.FileContent);
		}
		
		zip.Save(outputStream);
	}
	
	outputStream.Position = 0;
	string filename = "[filename].zip";
	return File(outputStream, "application/zip", filename);
}

Dian has written 11 articles

One thought on “Download File to ZIP Sample (Ionic.Zip)

Cancel reply

Leave a Reply to Randy Kurnia

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>