【发布时间】:2015-03-18 16:35:30
【问题描述】:
我正在创建一个 zip 文件并在我的项目中使用 c# 将其附加到电子邮件
我正在使用 DotNetZip。
下面是它的代码
Attachment attachment;
MemoryStream memoryStreamOfFile = new MemoryStream();
using (ZipFile zip = new ZipFile()) {
zip.Password = "123456";
zip.Encryption = EncryptionAlgorithm.WinZipAes256;
zip.AddEntry(FileName + ".csv", stream);
zip.Save(memoryStreamOfFile);
attachment = new Attachment(memoryStreamOfFile, new ContentType("application/zip")) {Name = FileName + ".zip"};
}
我实际上想要做的是我有byte[],我将其转换为 MemoryStream 并以 csv 格式添加到 zip 中,并将该 zip 文件附加到电子邮件中。
但是 zip 文件在电子邮件中是空的。我无法在我的驱动器中物理创建 zip 文件,我只能创建 MemoryStream。
我是不是做错了什么?
【问题讨论】:
标签: c# email email-attachments dotnetzip