ในบทความนี้จะขอกล่าวถึงการ download file ครั้งละหลายๆไฟล์ โดยมีการระบุว่าต้องการ download file ใดบ้าง โดย ผู้ใช้สามารถกดเลือกได้ทั้งละหลายๆไฟล์ หรือไฟล์เดียว แล้วแต่ความต้องการของผู้ใช้งาน โดยหลังจากที่มีการกดปุ่มแล้วระบบจะทำการ zip ไฟล์รวมเป็น 1 ไฟล์ โดยในบทความนี้จะขอเสนอวิธีการพัฒนาโดยใช้ ASP.NET ในรูปแบบ MVC ค่ะ ในส่วนของ java script function DownloadFiles() { var items = []; $(“input:checkbox[name=chkThis]:checked”).each(function () { items.push($(this).val()); }); if (items.length <= 0) { alert(‘กรุณาเลือกข้อมูลที่ต้องการ Download ด้วยค่ะ/ครับ!!’); } else { $.ajax({ type: ‘POST’, contentType: ‘application/json; charset=utf-8’, url: ‘@Url.Action(“DownloadAndZipFile”, “NoteUpload”)’, data: JSON.stringify({ fileItemsAll: items }), success: function (resultDownload) { //window.location = ‘/NoteUpload/Download?fileGuid=’ + resultDownload.FileGuid // + ‘&filename=’ + resultDownload.FileName; window.location = ‘/NoteUpload/Download?fileGuid=’ + resultDownload.FileGuid; }, error: function (data) { alert(data); } }); } // return items; } ในส่วนของ controller public ActionResult DownloadAndZipFile(IEnumerable<int> fileItemsAll) { if (!(ViewBag.IsAuthorized = (azResult = azService.Authorize(AccountingOperation.NoteUploadReader, this).Result).IsAuthorize)) { Danger(string.Format(“ไม่มีสิทธิ์ใช้งานในส่วนนี้: {0} ({1})”, azResult.Operation.OP_NAME, Convert.ToString(azResult.OperationEnum))); return View(); } string handle = Guid.NewGuid().ToString(); MemoryStream output = new MemoryStream(); var zipMs = new MemoryStream(); string strZipName = “Accounting” + DateTime.Now.ToString(“yyyyMMdd”); TempData[handle] = fileItemsAll; var resultDownload = new { FileGuid = handle, FileName = strZipName + “.zip” }; return this.Json(resultDownload, JsonRequestBehavior.AllowGet); } public FileResult Download(string fileGuid) { if (!(ViewBag.IsAuthorized = (azResult = azService.Authorize(AccountingOperation.NoteUploadReader, this).Result).IsAuthorize)) { Danger(string.Format(“ไม่มีสิทธิ์ใช้งานในส่วนนี้: {0} ({1})”, azResult.Operation.OP_NAME, Convert.ToString(azResult.OperationEnum))); return null; } var zipMs = new MemoryStream(); string zipFisYear, zipPeriod, fileC, FileF, FileFinance,