I am compressing a CSV file utilizing GZIPStream and MemoryStream, and noticing something weird with the result file. It seems like the CSV is not properly recognized. This shows when the file is attached to an email, but works fine when saved on a windows desktop.
Here is the current snippet handling the gzip portion:
GZipStream gStream = null;
MemoryStream mStream = null;
MemoryStream mStream2 = null;
try
{
if (attachment.Length > 0)
{
mStream = new MemoryStream();
gStream = new GZipStream(mStream, CompressionMode.Compress);
byte[] bytes = System.Text.Encoding.UTF8.GetBytes(attachment.ToString());
gStream.Write(bytes, 0, bytes.Length);
gStream.Close();
mStream2 = new MemoryStream(mStream.ToArray());
Attachment emailAttachement = new Attachment(mStream2, "myGzip.csv.gz", "application/x-Gzip");
mailMessage.Attachments.Add(emailAttachement);
}
}
All the suggested answers did not work. Found the answer here:
http://msdn.microsoft.com/en-us/magazine/cc163727.aspx