我正在尝试解压缩包含单个 txt 文件的 zip 文件。但我必须处理错误的流或什么,因为输出是一个空字符串。
content = new StreamReader(ms).ReadToEnd(); // content is ""
我使用 DotNetZip 开源包。知道这里缺少什么吗?
Attachment a = (from x in mail.Attachments.OfType<Attachment>()
where !string.IsNullOrEmpty(x.Body) || x.RawBytes != null
select x).FirstOrDefault();
AttachmentName = a.Name;
string AttachmentType = a.Name.Substring(a.Name.Length - 3, 3).ToUpper();
switch (AttachmentType)
{
case "ZIP":
MemoryStream ms = new MemoryStream();
using (ZipFile zip = ZipFile.Read(a.RawBytes))
{
foreach (ZipEntry e in zip)
e.Extract(ms);
}
content = new StreamReader(ms).ReadToEnd(); // content is ""
break;
default:
content = new StreamReader(new MemoryStream(a.RawBytes)).ReadToEnd();
break;