Author |
|
kmccmk9 Newbie
Joined: 10 April 2015
Online Status: Offline Posts: 1
|
Posted: 10 April 2015 at 12:52pm | IP Logged
|
|
|
Hello, I am attempting to read a Stream into a MailBee Attachment. Below is my code but, I receive the following error during execution:
Error:
Code:
MailBee.MailBeeInvalidArgumentException: The specified stream is closed or write-only.
at a.c.b(Stream A_0)
at MailBee.Mime.AttachmentCollection.Add(Stream stream, String targetFilename, String contentID, String contentType, HeaderCollection customHeaders, NewAttachmentOptions options, MailTransferEncoding mailEnc) |
|
|
Code:
Code:
foreach(ZipArchiveEntry entry in archive.Entries) {
if (entry.FullName.EndsWith(".xml", StringComparison.OrdinalIgnoreCase)) {
string path = Path.Combine(directory, entry.Name);
using(var stream = entry.Open())
using(StreamReader reader = new StreamReader(stream)) {
if (reader.ReadToEnd().Contains("hl7-org")) {
try {
msg.Attachments.Add(stream, entry.Name, "", null, null, NewAttachmentOptions.None, MailTransferEncoding.None);
} catch (Exception ex2) {
System.Diagnostics.EventLog.WriteEntry("Delivery Service", ex2.ToString());
}
}
}
}
}
|
|
|
Any help is much appreciated!
|
Back to Top |
|
|
Alex AfterLogic Support
Joined: 19 November 2003
Online Status: Offline Posts: 2206
|
Posted: 10 April 2015 at 4:06pm | IP Logged
|
|
|
Probably because you've already read the entire stream with ReadToEnd before passing it to MailBee. Nothing left in the stream. You can remove MailBee at from this sample and pass 'stream' variable to any other stream such as FileStream with the same effect.
Regards,
Alex
|
Back to Top |
|
|