locked
Crystal Reports emailing pdf attachments RRS feed

  • Question

  • User-154124751 posted

     Hello All,

    I'm trying to export a Crystal Report as a pdf file dynamically. The email part works fine, but the attached report gets sent as "Untitled.txt". I'm using the following code:

    Dim FileOptions As DiskFileDestinationOptions = New CrystalDecisions.Shared.DiskFileDestinationOptions

    FileOptions.DiskFileName = "TOP25.pdf"

    Dim rptOptions As CrystalDecisions.Shared.ExportOptions = New CrystalDecisions.Shared.ExportOptions

    rptOptions.ExportDestinationOptions = FileOptions

    Dim Dest As CrystalDecisions.Shared.MicrosoftMailDestinationOptions = New CrystalDecisions.Shared.MicrosoftMailDestinationOptions

    Dest.MailSubject = crParameterDiscreteValue.Value

    Dest.MailToList = jR.Item("EMail")

    Dim rptType As CrystalDecisions.Shared.ExportFormatType = ExportFormatType.PortableDocFormat

    rptOptions.ExportDestinationOptions = Dest

    rptOptions.ExportFormatType = rptType

    rptOptions.ExportDestinationType = ExportDestinationType.MicrosoftMail

    myRpt.Export(rptOptions)

    My question: is there anyway to give this export file a name and type?

     

    Thanks in advannce,

     

    Marc

    Monday, April 12, 2010 3:51 PM

Answers

  • User1668404196 posted

    Hi Good day, Please try the below code. And its working one (Currentl I'm using in my projects)

    Sub sendreportasmail(ByRef crm As ReportDocument)
            Dim ran As New Random
            Dim filename As String
    	'You must have write access to this path
            filename = Server.MapPath("temp\" & Now.ToString("yyyyMMddHHmmss") & ".pdf")
            crm.ExportToDisk(ExportFormatType.PortableDocFormat, filename)
            Dim obj As New MailMessage
            Dim att As New Attachment(filename)
            Dim smtp As New SmtpClient("your ip")
            obj.To.Add("To email address")
            obj.From = New MailAddress("From mail address")
            obj.Subject = "Subject"
            obj.IsBodyHtml = True
            obj.Body = "Body Content"
            obj.Attachments.Add(att)
            Try
                smtp.UseDefaultCredentials = True
                smtp.Send(obj)
            Catch ex As Exception
            End Try
    End Sub




    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, April 13, 2010 12:33 AM

All replies

  • User1668404196 posted

    Hi Good day, Please try the below code. And its working one (Currentl I'm using in my projects)

    Sub sendreportasmail(ByRef crm As ReportDocument)
            Dim ran As New Random
            Dim filename As String
    	'You must have write access to this path
            filename = Server.MapPath("temp\" & Now.ToString("yyyyMMddHHmmss") & ".pdf")
            crm.ExportToDisk(ExportFormatType.PortableDocFormat, filename)
            Dim obj As New MailMessage
            Dim att As New Attachment(filename)
            Dim smtp As New SmtpClient("your ip")
            obj.To.Add("To email address")
            obj.From = New MailAddress("From mail address")
            obj.Subject = "Subject"
            obj.IsBodyHtml = True
            obj.Body = "Body Content"
            obj.Attachments.Add(att)
            Try
                smtp.UseDefaultCredentials = True
                smtp.Send(obj)
            Catch ex As Exception
            End Try
    End Sub




    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, April 13, 2010 12:33 AM
  • User-154124751 posted

    Thank you Crajeshbe, that did the trick!

    Still wonder though why Microsoft created that transport method if it doesn't work!

     

    Marc 

    Tuesday, April 13, 2010 10:00 AM
  • User-1848975386 posted

    sir,

    I want to generate payslips of employees using crystal reports in a web application using asp.net and c#.so,that i can separate the payslips of each employee automatically and get it saved with a name or employee code in pdf format and send it through mail automatically.
    How can i generate the payslips for each employee in PDF separately and send it through email.
    kindly provide the code in c# .

    Thanks in advance.

    Thursday, April 4, 2013 8:54 AM