以下行给出了问题
content = new StreamReader(new GZipStream(new MemoryStream(a.RawBytes), CompressionMode.Decompress)).ReadToEnd();
发生 InvalidDataException:GZip 标头中的幻数不正确。确保您在 GZip 流中。
我可以不将附件转换为字节数组还是我做错了什么?
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":
content = new StreamReader(new GZipStream(new MemoryStream(a.RawBytes), CompressionMode.Decompress)).ReadToEnd();
break;
default:
content = new StreamReader(new MemoryStream(a.RawBytes)).ReadToEnd();
break;
}