Click here to Skip to main content
15,892,697 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,

I was sending multiple attachement but as suggested by someone, I need to convert it into the single zip. Can anyone suggest what change I need to implement in given code.

C#
public bool GetCertificatePDF(List<CPETSCertificate> objCPETSCertificate, string Name, string EmailId)
       {
           try
           {
               List<Attachment> lstAttachment = new List<Attachment>();
               int certificateCount = objCPETSCertificate.Count();
               string EnvironmentFrontEndUrl = System.Configuration.ConfigurationManager.AppSettings["EnvironmentFrontEndUrl"].ToString();
               for (int i = 0; i < certificateCount; i++)
               {
                   if (objCPETSCertificate[i].CourseName.Trim() != "" && objCPETSCertificate[i].CourseName.Trim() != null)
                   {
                       StreamReader stringHtml = System.IO.File.OpenText(System.Web.Hosting.HostingEnvironment.MapPath("~/assets/dictionary/lrn-cpets-certificate.html"));
                       string changeHtml = stringHtml.ReadToEnd();
                       if (certificateCount > 0 && certificateCount < 3)
                       {

                           changeHtml = changeHtml.Replace("##BG##", EnvironmentFrontEndUrl + "/assets/images/cpet/standard.jpg");
                       }
                       else if (certificateCount > 2 && certificateCount < 6)
                       {
                           changeHtml = changeHtml.Replace("##BG##", EnvironmentFrontEndUrl + "/assets/images/cpet/bronze.jpg");
                       }
                       else if (certificateCount > 6 && certificateCount < 10)
                       {
                           changeHtml = changeHtml.Replace("##BG##", EnvironmentFrontEndUrl + "/assets/images/cpet/silver.jpg");
                       }
                       else if (certificateCount == 10)
                       {
                           changeHtml = changeHtml.Replace("##BG##", EnvironmentFrontEndUrl + "/assets/images/cpet/gold.jpg");
                       }
                       changeHtml = changeHtml.Replace("##DictionaryListing##", Name.ToUpper());
                       changeHtml = changeHtml.Replace("##DictionaryListing2##", HttpUtility.UrlDecode(objCPETSCertificate[i].CourseName.ToUpper()));
                       if (objCPETSCertificate[i].CompletionDate != null)
                       {
                           changeHtml = changeHtml.Replace("##DictionaryListing3##", Convert.ToString(objCPETSCertificate[i].CompletionDate.ToString("dd-MMM-yyyy").Replace(" ", "")));
                       }
                       else
                       {
                           changeHtml = changeHtml.Replace("##DictionaryListing3##", string.Empty);
                       }
                       byte[] Certificate_PDF = GeneratePDFusingEvo(changeHtml, objCPETSCertificate[i].CourseName);
                       string CertificateName = (Name + "SiriusDecisions" + objCPETSCertificate[i].CourseName + objCPETSCertificate[i].CompletionDate.ToString("MM.dd.yyyy") + ".pdf").Replace(" ", "");
                       Attachment att = new Attachment(new MemoryStream(Certificate_PDF), CertificateName);
                       lstAttachment.Add(att);
                   }
               }
               bool flag = SendCPETSCertificate(Name, EmailId, lstAttachment);
               return flag;
           }
           catch (Exception ex)
           {
               Sitecore.Diagnostics.Log.Error(ex.Message, this);
               return false;
           }
       }


What I have tried:

As I am directly converting byte[] to attachment, I have not stored any physical file and I don't want to do it. Just need to convert List<attachment> to single zip
Posted
Updated 2-Dec-16 20:26pm

1 solution

Your classmates are also struggling!
See this from yesterday: How to zip multiple files to a single zip file in ASP.NET C#[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900