Search The ForumSearch   RegisterRegister  LoginLogin

MailBee.NET Objects

 AfterLogic Forum : MailBee.NET Objects
Subject Topic: Specified Stream is closed or write-only Post ReplyPost New Topic
Author
Message << Prev Topic | Next Topic >>
kmccmk9
Newbie
Newbie


Joined: 10 April 2015
Online Status: Offline
Posts: 1
Posted: 10 April 2015 at 12:52pm | IP Logged Quote kmccmk9

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 View kmccmk9's Profile Search for other posts by kmccmk9
 
Alex
AfterLogic Support
AfterLogic Support
Avatar

Joined: 19 November 2003
Online Status: Offline
Posts: 2206
Posted: 10 April 2015 at 4:06pm | IP Logged Quote Alex

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 View Alex's Profile Search for other posts by Alex
 

If you wish to post a reply to this topic you must first login
If you are not already registered you must first register

  Post ReplyPost New Topic
Printable version Printable version

Forum Jump

Powered by Web Wiz Forums version 7.9
Copyright ©2001-2004 Web Wiz Guide