YOU DID ITTT!~!!!~!!@#!#!@#!@#! WWOO0000tttttt
I completed reconstructed my methods like you i used "GET" instead of "POST" because for some reason my project isn't letting my use POST But I got it working both PDFs are as they are suppose to be in the zip now.
I created a Model like you and thats how i did it.
[HttpGet]
public virtual ActionResult DownloadAsZip(string mimeType)
{
if (TempData["Files"] != null)
{
List<ServiceFile> lstFiles = TempData["Files"] as List<ServiceFile>;
byte[] bytearray = null;
using (MemoryStream ms = new MemoryStream())
{
// Creates the .zip
using (ZipArchive archive = new ZipArchive(ms, ZipArchiveMode.Create, true))
{
foreach (ServiceFile file in lstFiles) // iterate through each file
{
// Creates empty file and names it inside of .zip
ZipArchiveEntry zipItem = archive.CreateEntry(file.FileName + file.Extension);
// adds file to zipItem
using (MemoryStream ms4file = new MemoryStream(file.FileBytes))
{
using (Stream stream = zipItem.Open())
{
ms4file.CopyTo(stream);
}
}
}
}
bytearray = ms.ToArray();
}
return File(bytearray, "application/zip");
}
else
{
return new EmptyResult();
}
}
public ActionResult ExportFiles(int[] quoteIDs)
{
List<ServiceFile> lstFiles = new List<ServiceFile>();
if (quoteIDs != null)
{
string command = "PDF";
string reportType = command;
string mimeType = "", encoding = "", fileNameExtension = "";
foreach (var qid in quoteIDs)
{
List<ServiceQuote> lstQuotes = new List<ServiceQuote>();
var quote = context.ServiceQuotes.Where(x => x.QuoteID == qid).FirstOrDefault();
lstQuotes.Add(quote);
LocalReport localReport = new LocalReport()
{
ReportPath = Server.MapPath("~/ReportForms/VirtualService3.rdlc")
};
ReportDataSource reportDataSource = new ReportDataSource("Service_Fields", lstQuotes);
localReport.DataSources.Add(reportDataSource);
string deviceInfo =
"<DeviceInfo>" +
" <OutputFormat>" + reportType + "</OutputFormat>" +
" <PageWidth>8.5in</PageWidth>" +
" <PageHeight>11in</PageHeight>" +
" <MarginTop>0in</MarginTop>" +
" <MarginLeft>0in</MarginLeft>" +
" <MarginRight>0in</MarginRight>" +
" <MarginBottom>0in</MarginBottom>" +
"</DeviceInfo>";
Warning[] warnings;
string[] streams;
byte[] renderedBytes = localReport.Render(reportType, deviceInfo, out mimeType, out encoding,
out fileNameExtension, out streams, out warnings);
lstFiles.Add(new ServiceFile { Extension = "." + fileNameExtension, FileName = qid.ToString(), FileBytes = renderedBytes });
}
TempData["Files"] = lstFiles;
//return new JsonResult() { Data = new { MimeType = mimeType } };
return Json(mimeType, JsonRequestBehavior.AllowGet);
//return File(renderedBytes, mimeType);
}
return RedirectToAction("VirtualService");
}