---
title: "File download in zip Folder in ASP.NET MVC 4"  
description: "In this blog have described how to download multiple files within a zip folder in ASP.NET MVC 4. This is also help full in C# and ASP.NET C#.   Steps"  
author: "AVADHESH PATEL"  
published: 2013-02-02  
updated: 2014-09-18  
canonical: https://www.mindstick.com/blog/439/file-download-in-zip-folder-in-asp-dot-net-mvc-4  
category: "asp.net mvc"  
tags: ["asp.net mvc"]  
reading_time: 2 minutes  

---

# File download in zip Folder in ASP.NET MVC 4

In this blog have described how to download [multiple files](https://www.mindstick.com/forum/33990/attach-multiple-files-gridview-row-in-knockout-js) within a zip folder in [ASP.NET MVC](https://www.mindstick.com/forum/155798/what-is-caching-in-asp-dot-net-mvc) 4. This is also help full in C# and [ASP.NET C#](https://www.mindstick.com/forum/435/textchange-event-at-server-side-using-javascript-in-asp-dot-net-c-sharp). Steps are given below.\

Step 1: For downloading files in compressed folder (Zip Folder), first you download one DDL file “ICSharpCode.SharpZipLib.Zip”, because this DDL is required for downloading files in zip folder. You can download this DDL from below link.

http://www.icsharpcode.net/opensource/sharpziplib/

Step 2: [Add reference](https://www.mindstick.com/forum/548/how-to-add-reference-to-system-web-optimization) of downloaded DDL (ICSharpCode.SharpZipLib.Zip) and used two [namespaces](https://www.mindstick.com/forum/155583/what-are-namespaces-in-c-sharp) in [your project](https://www.mindstick.com/forum/156583/best-way-to-link-bootstrap-file-in-your-project) which given below.

using ICSharpCode.SharpZipLib.Zip;

using System.IO;

Step 3: Now used below line of code within your action or where you want.

```
using (var zipStream = new ZipOutputStream(Response.OutputStream)){// Give the file name of downloaded zip file  Response.AddHeader("Content-Disposition", "attachment; filename=Description.zip");// Define content type   Response.ContentType = "application/zip";// Get all file path one by one  foreach (var path in list)  {              // Get every file size                byte[] fileBytes = System.IO.File.ReadAllBytes(Server.MapPath(path.FilePath));              // Get every file path                var fileEntry = new ZipEntry(Path.GetFileName(Server.MapPath(path.FilePath)))                {                     Size = fileBytes.Length                };        zipStream.PutNextEntry(fileEntry);        zipStream.Write(fileBytes, 0, fileBytes.Length);    } // Clear and closed zipStream object  zipStream.Flush();  zipStream.Close();}
```

Step 4: If you want to download [single file](https://www.mindstick.com/forum/161633/how-do-you-merge-multiple-text-files-into-a-single-file) than try below line of code.

```
// Define content type Response.ContentType = "application/pdf";// set the file name of fileResponse.AppendHeader("Content-Disposition", "attachment; filename=Description.pdf");// get file path from server sideResponse.TransmitFile(Server.MapPath("~/content/Description.pdf"));Response.End();
```

**Note**: Trim or remove blank spaces before [file upload](https://www.mindstick.com/articles/13047/file-upload-and-download-in-mvc) and download from [file name](https://www.mindstick.com/interview/34109/how-do-you-generate-a-unique-file-name-to-avoid-overwriting-an-existing-one).

---

Original Source: https://www.mindstick.com/blog/439/file-download-in-zip-folder-in-asp-dot-net-mvc-4

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
