The information stored in memorystream in itextsharp cannot be used as an email attachment.

Source: Internet
Author: User
When itextsharp was used, there was a small problem. otherwise, this is indeed a very convenient and perfect component, but some domestic online solutions are copied and searched. They are all the same, which is quite disgusting. when using itextsharp, if you need to write the generated PDF content to stream, note that stream will be closed by the itextsharp object. otherwise, an error "can not access with closed stream" is reported when streaming operations are performed."
  1. Using writer. getinstance (document, stream). closestream =False;

Another problem is that when itextsharp writes the stream to memorystream, if the stream is used as an attachment, the stream pointer needs to be moved to the starting place, otherwise, the attachment may be a file with an error of 0.

  1. Memorystream attachment =This. Generatepdf ();
  2. Attachment. Seek (0, seekorigin. Begin );

In this way, you can use the attachment in system. net. Mail to add an attachment.

If streamwriter is used, flush () is required before generation.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.