Advertisement
Guest User

Untitled

a guest
Aug 30th, 2016
53
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.92 KB | None | 0 0
  1. using (Stream XmlPartStream = new MemoryStream())
  2. using (XmlTextWriter XmlPartWriter = new XmlTextWriter(XmlPartStream, Encoding.Unicode))
  3. {
  4. XDocument TheXInvoice = TheInvoice.XInvoice(dtInvoiceLines);
  5. XmlPartWriter.Formatting = Formatting.Indented;//xml output will be pretty-printed
  6. TheXInvoice.WriteTo(XmlPartWriter);//write to the MemoryStream
  7. XmlPartWriter.Flush();//finish writing to MemoryStream
  8.  
  9. XmlPartStream.Seek(0, SeekOrigin.Begin);//rewind stream (Position=0 would also work)
  10. Attachment XmlPart = new Attachment(XmlPartStream, InvoiceXmlName, "application/xml");
  11. TheMail.Attachments.Add(XmlPart);
  12. XmlPartStream.Flush();//finish writing from MemoryStream to Attachment
  13. // BUG: no bytes in the Attachment
  14.  
  15. XmlPartStream.Seek(0, SeekOrigin.Begin);//rewind stream (Position=0 would also work)
  16. byte[] ZippedXml = LempelZiv.GZip(XmlPartStream);
  17. // OK: Entire XML in the ZippedXml
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement