예제 #1
0
파일: ZipHelper.cs 프로젝트: rivernli/SGP
 public static void PDFToZip(string[] ids, MemoryStream mem)
 {
     if (ids != null && ids.Length > 0)
     {
         using (ZipFile f = ZipFile.Create(mem))
         {
             f.BeginUpdate();
             foreach (string id in ids)
             {
                 int entityId = 0;
                 if (int.TryParse(id, out entityId) && entityId > 0)
                 {
                     MemoryStream mstream = new MemoryStream();
                     PDFDownLoad pdf = new PDFDownLoad();
                     string fileName;
                     if (pdf.getPDF(ref mstream, entityId, out fileName))
                     {
                         f.Add(new MemoryDataSource(mstream.GetBuffer()), fileName + ".pdf");
                     }
                 }
             }
             f.CommitUpdate();
         }
     }
 }
예제 #2
0
        public FileResult DownloadPDF()
        {
            string KeyValues = Request.QueryString["RFQID"];
            string fileName = "";
            string tempFile = System.Web.HttpContext.Current.Server.MapPath("~/temp/" + Guid.NewGuid() + ".tmp");
            MemoryStream mem = new MemoryStream();
            if (!String.IsNullOrEmpty(KeyValues))
            {
                KeyValues = KeyValues.TrimEnd(',');
                string[] ids = KeyValues.Split(',');
                if (ids.Length == 1)
                {
                    int id = Int32.Parse(ids[0]);

                    BI.SGP.BLL.Models.PDFDownLoad pdf = new PDFDownLoad();
                    if (pdf.getPDF(ref mem, id, out fileName))
                    {

                        if (fileName == "")
                        {
                            fileName = "multek_" + DateTime.Now.ToString("mmssffff") + ".pdf";
                        }
                        else
                        {
                            fileName += ".pdf";
                        }
                        using (var fileStream = FileHelper.CreateFile(tempFile))
                        {
                            fileStream.Write(mem.GetBuffer(), 0, mem.GetBuffer().Length);
                        }
                    }
                }
                else
                {
                    ZipHelper.PDFToZip(ids, mem);
                    fileName = "PDF_Packages_" + DateTime.Now.ToString("mmss") + ".zip";
                    using (var fileStream = FileHelper.CreateFile(tempFile))
                    {
                        mem.WriteTo(fileStream);
                    }
                }
            }

            return File(tempFile, "application/octet-stream", fileName);
        }