1
votes

I'd like to be able to create, name and store individualized reports (school report cards, actually) with VB.Net and Crystal Reports using data from our SQL database.

It would be even better to be able to automatically generate individualized e-mails using e-mail addresses stored in the database, attaching the aforementioned PDF reports and sending them off.

Has anyone attempted anything like this before?

TIA for any help/pointers!

1
Loop over all the student records, passing the unique student ID to the report as a parameter and then export the report to PDF. Attach the PDF to a mail message. This could be done in ~30 LOC. What specifically are you having trouble with? Sorry, but it sounds like you're asking for a complete solution without even trying anything first.Paul Abbott
Thanks for the response. I kinda got the overall concept. I'm already passing the IDs as parameters to the ReportViewer and producing the reports as one big batch, which I then just print and snail-mail. I just haven't seen any code to get the Crystal ReportViewer to export the PDF programmatically, nor do I know how to programmatically create the e-mail and attach the appropriate PDF. I'll do more research. If it can be done in 30 LOC, then I guess I can find some pointers somewhere as to how to put that code together.user180433

1 Answers

1
votes

1. Create PDF programatically

Depending on the version of crystal, the export function will look similar to this

Dim objApp As CRAXDRT.Application
Dim objRpt As CRAXDRT.Report
Dim Path As String = "MyReport.rpt"

objApp = new CRAXDRT.Application
objRpt = objApp.OpenReport(Path)

With objRpt
   .ExportOptions.FormatType = crEFTPortableDocFormat
   .ExportOptions.DestinationType = crEDTDiskFile
   .ExportOptions.DiskFileName = "MyReport.PDF"
   .ExportOptions.PDFExportAllPages = True
   .Export( False )
End With

2. Send email with a PDF attachment

The "send" part will look like this:

Dim email As New MailMessage()

''//set the reply to address and the to address
email.To.Add(New MailAddress("[email protected]", "Studen Name"))
email.ReplyTo = New MailAddress("[email protected]", "Your name")


''//Assign the MailMessage's properties
email.Subject = "Your scorecard file"
email.Body = "Attached is the file you asked<br />Regards!"
email.IsBodyHtml = True

''//attach the file
email.Attachments.Add(New Attachment("c:\temp\myreport.pdf"))


Dim smtp As New SmtpClient
Try
    smtp.Send(email)
Catch ex As Exception
    messageBox("cant send")
End Try