---
title: "pdf file not download in mvc4 custom checkbox?"  
description: "pdf file not download in mvc4 custom checkbox?"  
author: "marcel ethan"  
published: 2013-03-01  
updated: 2013-03-02  
canonical: https://www.mindstick.com/forum/616/pdf-file-not-download-in-mvc4-custom-checkbox  
category: "asp.net mvc"  
tags: ["asp.net mvc"]  
reading_time: 3 minutes  

---

# pdf file not download in mvc4 custom checkbox?

Hi Everyone!

I have using [model popup](https://www.mindstick.com/forum/34333/how-i-can-call-a-model-popup-with-data-by-using-jquery-in-mvc) for selecting [files](https://www.mindstick.com/articles/23302/the-importance-and-advantage-of-keeping-your-important-files-on-the-cloud) for [download](https://www.mindstick.com/articles/188403/website-to-download-photos-from-instagram) in zip formate. Here i have used [custom checkbox](https://www.mindstick.com/blog/455/custom-checkbox-using-css) usind css. my line of code are given below

Checkbox code. Here checkbox are generated dynamicaly

```
           <table>                @foreach (var item in Model)                {                    <tr>                        <td>                            <span class="custom-checkbox">                                <input id="fileItem@(item.AttachmentID)" name="fileItem@(item.AttachmentID)" type="checkbox" class="ckbox" value="1" />                                <span class="box" style="background-color: #E5E5E5"><span class="tick"></span></span>                            </span>                            <input id="fileId" name="fileId" type="hidden" value="@item.AttachmentID" />                        </td>                        <td>                            <label for="fileItem@(item.AttachmentID)">@Truncate(item.Description, 30)</label>                        </td>                    </tr>                }            </table>            <input id="btnDownload" type="submit" value="Download" />
```

Checkbox css

```
.ckbox{ width: 25px; height: 25px;}.custom-checkbox{ position: relative; display: inline-block;}.custom-checkbox > .box{ position: relative; display: block; width: 25px; height: 25px; background-color: #E5E5E5; padding: 0px; margin: 0px;}.custom-checkbox > .box > .tick{ position: absolute; left: 4px; top: 7px; width: 14px; height: 6px; border-bottom: 4px solid #000; border-left: 4px solid #000; -webkit-transform: rotate(-45deg); -moz-transform: rotate(-45deg); -o-transform: rotate(-45deg); -ms-transform: rotate(-45deg); transform: rotate(-45deg); display: none;}.custom-checkbox > input:checked + .box > .tick{ display: block;}.custom-checkbox > input{ position: absolute; outline: none; left: 0; top: 0; padding: 0; width: 25px; height: 25px; border: none; margin: 0; opacity: 0; z-index: 1;}.td_user{ padding: 9px 0px 5px 9px;}.lblFontStyle{ font-family: TradeGothic; font-style: oblique; font-size: 16px; color: #000;}
```

## MVC [Action](https://www.mindstick.com/forum/155752/what-is-action-result-with-its-types) Code

```
 [HttpPost]        public ActionResult AttachmentList(FormCollection formData)        {            var fileIds = formData["fileId"].Split(',');            var selectedIndices = formData["fileItem"].Replace("true,false", "true").Split(',').Select((item, index) => new            {                item = item,                index = index            }).Where(row => row.item == "true").Select(row => row.index).ToArray();            if (selectedIndices.Count() > 1)            {                using (var zipStream = new ICSharpCode.SharpZipLib.Zip.ZipOutputStream(Response.OutputStream))                {                    foreach (var index in selectedIndices)                    {                        Response.AddHeader("Content-Disposition", "attachment; filename=ProductDescription.zip");                        Response.ContentType = "application/zip";                        int attachid = int.Parse(fileIds[index]);                        foreach (Attachment filePath in dbZytron.Attachment.Where(m => m.AttachmentID == attachid))                        {                            byte[] fileBytes = System.IO.File.ReadAllBytes(Server.MapPath(filePath.FilePath));                            var fileEntry = new ICSharpCode.SharpZipLib.Zip.ZipEntry(System.IO.Path.GetFileName(Server.MapPath(filePath.FilePath)))                            {                                Size = fileBytes.Length                            };                            zipStream.PutNextEntry(fileEntry);                            zipStream.Write(fileBytes, 0, fileBytes.Length);                        }                    }                    zipStream.Flush();                    zipStream.Close();                }            }            else            {                int attachid = int.Parse(fileIds.ElementAt(selectedIndices.ElementAt(0)));                Attachment filePath = dbZytron.Attachment.FirstOrDefault(m => m.AttachmentID == attachid);                if (filePath != null)                {                    Response.ContentType = "application/pdf";                    Response.AppendHeader("Content-Disposition", "attachment; filename=" + filePath.Description + "" + ".pdf");                    Response.TransmitFile(Server.MapPath(filePath.FilePath));                    Response.End();                }            }            return Content(null);        }
```

Please help me

Thanks in [advance](https://www.mindstick.com/blog/33258/jee-mains-and-jee-advance-exams)

## Replies

### Reply by AVADHESH PATEL

Hi Marcel!

replace below action controll (AttachmentList) from your action controll (AttachmentList)

[HttpPost]\
public ActionResult AttachmentList(FormCollection formData)\
{\
var fileIds = formData["fileId"].Split(',');\
List<string> list = new List<string>();\
foreach (var id in fileIds)\
{\
if (!string.IsNullOrEmpty(formData["fileItem" + id]) && Convert.ToBoolean(int.Parse(formData["fileItem" + id])))\
list.Add(id);\
}

if (list.Count() > 1)\
{\
using (var zipStream = new ICSharpCode.SharpZipLib.Zip.ZipOutputStream(Response.OutputStream))\
{\
foreach (var index in list)\
{\
Response.AddHeader("Content-Disposition", "attachment; filename=ProductDescription.zip");\
Response.ContentType = "application/zip";

int attachid = int.Parse(index);\
foreach (Attachment filePath in dbZytron.Attachment.Where(m => m.AttachmentID == attachid))\
{\
byte[] fileBytes = System.IO.File.ReadAllBytes(Server.MapPath(filePath.FilePath));

var fileEntry = new ICSharpCode.SharpZipLib.Zip.ZipEntry(System.IO.Path.GetFileName(Server.MapPath(filePath.FilePath)))\
{\
Size = fileBytes.Length\
};

zipStream.PutNextEntry(fileEntry);\
zipStream.Write(fileBytes, 0, fileBytes.Length);\
}\
}\
zipStream.Flush();\
zipStream.Close();\
}\
}\
else\
{\
int attachid = int.Parse(list.ElementAt(0));\
Attachment filePath = dbZytron.Attachment.FirstOrDefault(m => m.AttachmentID == attachid);\
if (filePath != null)\
{\
Response.ContentType = "application/pdf";\
Response.AppendHeader("Content-Disposition", "attachment; filename=" + filePath.Description + "" + ".pdf");\
Response.TransmitFile(Server.MapPath(filePath.FilePath));\
Response.End();\
}\
}\
\
return Content(null);\
}


---

Original Source: https://www.mindstick.com/forum/616/pdf-file-not-download-in-mvc4-custom-checkbox

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
