Exporting Report to PDF and Sending as Email Attachment from Website
Posted: Thu Sep 13, 2007 11:57 pm
I am displaying a report using the web viewer control and when a button on the page is clicked I want it to generate a pdf document from the report and send it as an attachment. I am using .NET Framework 2.0 and version 2007.2 of Stimulsoft Reports.
I want to be able to export the report to pdf and send it as an attachment without having to save the pdf to disk first.
Below is my code so far:
At the moment the email is sent with a pdf attached but the filesize is 64 bytes instead of 33,000 bytes and can't be opened by adobe acrobat.
Any ideas on how I best go about this?
I want to be able to export the report to pdf and send it as an attachment without having to save the pdf to disk first.
Below is my code so far:
Code: Select all
Private Sub SendReport()
Dim stream As IO.MemoryStream
Dim smtp As Mail.SmtpClient
Dim item As Mail.MailMessage
Dim attachment As Mail.Attachment
Dim report As Stimulsoft.Report.StiReport
Try
'Get Report
report = StiWebViewer.Report
'Create Mail Message
item = New Mail.MailMessage("", "")
item.Subject = "Test Report"
item.Body = "Attached is a report."
'Create Attachment
stream = New IO.MemoryStream
report.ExportDocument(Stimulsoft.Report.StiExportFormat.Pdf, stream)
attachment = New Mail.Attachment(stream, "MyReport.pdf", "application/pdf")
item.Attachments.Add(attachment)
'Create SMTP Client
smtp = New Mail.SmtpClient
smtp.Host = ""
smtp.Send(item)
Catch ex As Exception
lblError.Text = "An error occured while trying to generate report."
End Try
End Sub
Any ideas on how I best go about this?