Exporting crystal report as PDF and sending via email as attachment - Filename Issue? RRS feed

  • Question


    I need to export a crystal report as a pdf and send it out via email.  I have created a subroutine that works but the attached filename come up as "untitled.txt" so the receiving machine believes it is a text file.  If I rename it on the recipients machine to a ".pdf" I can open it with acrobat and it looks OK.  Does anyone know how to rename the file as a pdf prior to sending it out? 

    Thank You.



    I have included a copy of the subroutine:


    Dim repdoc As New CrystalDecisions.CrystalReports.Engine.ReportDocument()

    Dim diskOpts As New CrystalDecisions.Shared.DiskFileDestinationOptions()

    Dim ExpOpts As CrystalDecisions.Shared.ExportOptions

    Dim MailOpts As New CrystalDecisions.Shared.MicrosoftMailDestinationOptions()

    repdoc = Me.CrystalReport11

    repdoc.Load("C:\Documents and Settings\User\My Documents\Visual Studio 2005\Projects\WindowsApplication3\WindowsApplication3\CrystalReport1.rpt")

    ExpOpts = repdoc.ExportOptions

    With ExpOpts

    .ExportDestinationType = CrystalDecisions.[Shared].ExportDestinationType.MicrosoftMail

    .ExportFormatType = CrystalDecisions.[Shared].ExportFormatType.PortableDocFormat

    End With

    With MailOpts

    .MailMessage = "Message"

    .MailToList = "enter email adress here"

    .MailSubject = "Attached is a PDF file - .net Export test "

    End With

    ExpOpts.DestinationOptions = MailOpts



    Catch err As Exception


    End Try


    End Sub

    Friday, October 19, 2007 3:58 PM

All replies

  • I have the same, unresolved, problem. Did you find any solutions?


    Tnx, Andrea.


    Wednesday, November 14, 2007 2:41 PM
  • I didn't find the solution, but I found a way around it.  First I used the crystal reports export function to save it as a pdf and then I used netmail to attach it to an email and send it out.

    Hope this helps.  I could send you a copy of the routine if you need it.


    Wednesday, November 14, 2007 4:29 PM
  • A copy of that code will be very appreciated... :-)


    Thanks, Andrea.

    Thursday, November 15, 2007 11:20 AM

    Hi Alynch


    I am facing exactly the same problem what you have mentioned.

    Please let me know urgently if you fixed this issue.


    All others ! did some one find a solution for this issue ?

    Tuesday, April 22, 2008 8:52 AM
  • Tuesday, December 16, 2008 10:43 AM
  • Hi found the solution for this what you have to do is first export it to some xyz.PDF and then send it as attchment. The code for this has been written below in C#.net

    string pdfFile = "c:\\CrytalReport.pdf";

    protected void Button1_Click(object sender, EventArgs e)
                ExportOptions CrExportOptions;
                DiskFileDestinationOptions CrDiskFileDestinationOptions = new DiskFileDestinationOptions();
                PdfRtfWordFormatOptions CrFormatTypeOptions = new PdfRtfWordFormatOptions();
                CrDiskFileDestinationOptions.DiskFileName = pdfFile;
                CrExportOptions = ReportDocument .ExportOptions;//Report document  object has to be given here
                CrExportOptions.ExportDestinationType = ExportDestinationType.DiskFile;
                CrExportOptions.ExportFormatType = ExportFormatType.PortableDocFormat;
                CrExportOptions.DestinationOptions = CrDiskFileDestinationOptions;
                CrExportOptions.FormatOptions = CrFormatTypeOptions;
                ReportDocument .Export();

            catch (Exception ex)

        private void sendmail()
                MailMessage Msg = new MailMessage();
                Msg.To = "to Address";
                Msg.From = "From Address";
                Msg.Subject = "Crystal Report Attachment ";
                Msg.Body = "Crystal Report Attachment ";
                Msg.Attachments.Add(new MailAttachment(pdfFile));
               // System.Web.Mail.SmtpMail.Send(Msg);

                SmtpMail.SmtpServer = "you mail domain";

            catch (Exception ex)

    Dont forget add these DLL's

    using CrystalDecisions.CrystalReports.Engine;
    using CrystalDecisions.Shared;


    Hope this helps !!!!!!!!!!!!!

    Have a nice programming....................

    • Proposed as answer by SAPDon Tuesday, February 15, 2011 1:12 AM
    Thursday, May 6, 2010 9:33 AM
  • Sunday, October 17, 2010 6:37 AM