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.
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