在电子邮件中将多个附件转换为单个zip [英] Convert multiple attachment to single zip in email
本文介绍了在电子邮件中将多个附件转换为单个zip的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我发送多个附件但是根据某人的建议,我需要将其转换为单个拉链。任何人都可以建议我需要在给定代码中实现哪些更改。
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;
}
}
我的尝试:
因为我直接将byte []转换为附件,所以我没有存储任何物理文件而且我不想这样做。只需要转换List< attachment>单个拉链
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
推荐答案
你的同学也在苦苦挣扎!
从昨天看这个:如何在ASP.NET C#中将多个文件压缩为单个zip文件/ a> [ ^ ]
Your classmates are also struggling!
See this from yesterday: How to zip multiple files to a single zip file in ASP.NET C#[^]
这篇关于在电子邮件中将多个附件转换为单个zip的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文