Using a c# windows form I would like to convert some text to a stream, encode as HTM then add into a ZIP stream (always 1 HTM file Zipped/protected) and then email out (passing the stream) as parameter to MailMessage. (all without saving to disk)
using (MailMessage email = new MailMessage())
..... <some code>
Attachment attach = new Attachment(zipFile);
Firstly, I am wondering if this is possible?
I have attempted to do this:
MemoryStream ms = new MemoryStream();
using (ZipFile zip = new ZipFile())
zip.AddFileFromString(htm_filename, "", htm_data);
Console.WriteLine("Output stream Length: " + ms.Length + " CanWrite: " + ms.CanWrite + " Capacity: " + ms.Capacity + " CanRead: " + ms.CanRead);
But when using below to read the stream (for testing purposes) :
MemoryStream os = new MemoryStream();
using (ZipFile ez = ZipFile.Read(ms))
Console.WriteLine("Output stream Length: " + os.Length + " CanWrite: " + os.CanWrite + " Capacity: " + os.Capacity + " CanRead: " + os.CanRead);
I get an error with output... (below)
Output stream Length: 130 CanWrite: True Capacity: 256 CanRead: True
Error: Could not read block - no data! (position 0x00000082)
So it appears as if saving the ms stream but not able to read it back... ?
Thank you for any assistance on this.