使用sharpPDF库,我生成了一个 pdf 内存流,我想直接通过电子邮件发送它。但是行 ms.Seek(.... 给出了 ObjectDisposedException;
无法访问已关闭的 Stream。
pdf.CreatePDF 方法采用(输出)文件名字符串或(输出)流。但我想它也会关闭流?我不习惯使用流,所以如果你能告诉我应该怎么做?
CreatePDF方法的sharpPDF源代码可以在这里找到:
http://www.java2s.com/Open-Source/CSharp/PDF/SharpPDF/sharpPDF/pdfDocument.cs.htm
Public Sub SendPDF()
Dim pdf As New sharpPDF.pdfDocument("Title", "Author")
'....Generate pdf content
Dim ms As New IO.MemoryStream
pdf.CreatePDF(ms)
Dim email As New EmailService
email.Send(ms)
End Sub
Public Class EmailService
Public Sub Send(Byval ms as Stream)
ms.Seek(0, IO.SeekOrigin.Begin)
Dim atc As New Attachment(ms, "Report.pdf")
mail.Attachments.Add(atc)
'....set other email parameters
client.SendAsync(mail, mail.Subject)
End Sub
End Class