Reputation: 6547
The following line gives problems
content = new StreamReader(new GZipStream(new MemoryStream(a.RawBytes), CompressionMode.Decompress)).ReadToEnd();
InvalidDataException occurred: The magic number in GZip header is not correct. Make sure you are in a GZip stream.
can I not convert the attachment to a byte array or what am I doing wrong?
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;
}
Upvotes: 0
Views: 342
Reputation: 956
A GZip file is not the same thing as a Zip file. You want System.IO.Compression.ZipFile or ZipArchive.
Upvotes: 4