Link to home
Start Free TrialLog in
Avatar of Éric Moreau
Éric MoreauFlag for Canada

asked on

Email report directly from the Crystal viewer

Hi

I am using Crystal Reports bundled with VS2008.

A client asked me to add a feature to e-mail the report he currently sees in the viewer. I looked around the properties of the viewer and saw nothing that does that.

So I have added a plain old button to my viewer form and pasted this code I found googling (I am not sure it is related to this version of CR):
    Private Sub btnEmail_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnEmail.Click
        Dim pdfOpts As PdfRtfWordFormatOptions = ExportOptions.CreatePdfRtfWordFormatOptions()
        Dim mailOpts As MicrosoftMailDestinationOptions = ExportOptions.CreateMicrosoftMailDestinationOptions()
        Dim exportOpts As ExportOptions = New ExportOptions

        pdfOpts.UsePageRange = False
        exportOpts.ExportFormatOptions = pdfOpts

        exportOpts.ExportDestinationOptions = mailOpts

        exportOpts.ExportDestinationType = ExportDestinationType.MicrosoftMail
        exportOpts.ExportFormatType = ExportFormatType.PortableDocFormat

        With DirectCast(Me.Viewer.ReportSource, CrystalDecisions.CrystalReports.Engine.ReportDocument)
            .Export(exportOpts)
        End With
    End Sub

With this code, an "InvalidArgumentException" is raised on the .Export line. The Message is "Invalid export options".

Is this the correct way to e-mail the report? Is there another method?
Avatar of Shahan Ayyub
Shahan Ayyub
Flag of Pakistan image

Avatar of Éric Moreau

ASKER

My question is about sending the report directly from the viewer and not saving it first in a PDF file and then attach it to a SMTP mail which the user doesn't want (he wants his default e-mail application to handle it).
that doesn't work!

on http://msdn.microsoft.com/en-us/library/ms226415(v=VS.90).aspx, I can read: "To successfully export to Microsoft mail, the system first needs to have loaded mapisp32.dll. Mapisp32.dll can be loaded by running the mail client, for example Microsoft Outlook."

I have Outlook installed but I don't find Mapisp32.dll. Does somebody has it?
Avatar of Mike McCracken
Mike McCracken

There should be an export button on the viewer.  It looks like an envelope
If you click it do you see the EMAIL or MAPI option?

If not then the export dlls aren't installed.

Is this on the development machine with VS2008 installed or a client?

If a client then what did you install on the client and the server?

mlmcc
Hi mlmcc

I saw that envelop icon on older version of the viewer (remember I am using the version bundled with VS2008). I don't see it in the current version (see image attached).

When I click the Export button, it only offers me files options (see the second menu).

Those images are coming from my developement PC. Do you have an idea of which dlls are not installed because when we install it, it is much an all or nothing option!
menu1.jpg
menu2.jpg
ASKER CERTIFIED SOLUTION
Avatar of Éric Moreau
Éric Moreau
Flag of Canada image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
AFAIK Export option allows to export item in different software. I tested export option of the Built-in CrystalReportViewer it saves file on my desktop. So, you should send that file through smtp.
I cannot use SMTP or I have to rebuild Outlook completly to give user access to his list of contacts!
I tried to attach file like this but no good luck:

    Private Sub CrystalReportViewer1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CrystalReportViewer1.Click
        CrystalReport11.ExportToDisk(CrystalDecisions.Shared.ExportFormatType.CrystalReport, "C:\Documents and Settings\Shahan.COREI3\Desktop\abc.rpt")
        Dim filename As String = "C:\Documents and Settings\Shahan.COREI3\Desktop\abc.rpt"
        Process.Start("mailto:eng.shahan@gmail.com")
        'Process.Start("mailto:eng.shahan@gmail.com /attachment:" + filename)  'not working
    End Sub

Does it shed some light on the solution??
the attachment argument is not supported by Outlook and many other applications. I might have found something that I will only be able to test tomorrow
I have seen that this works if Outlook Express is set as default:

    Private Sub CrystalReportViewer1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CrystalReportViewer1.Click
        CrystalReport11.ExportToDisk(CrystalDecisions.Shared.ExportFormatType.CrystalReport, "C:\Documents and Settings\Shahan.COREI3\Desktop\abc.rpt")
        Dim filename As String = "C:\Documents and Settings\Shahan.COREI3\Desktop\abc.rpt"
      Process.Start("mailto:eng.shahan@gmail.com?subject=Pictures from PhotoAlbum&cc=eng.shahan@gmail.com&body=This is the body text&attachment='" & filename "'")
    End Sub
Okay I read your last comment.
Nobody is using Outlook Express anymore!
Is your mail server running a MAPI mail program?
Crystal can only use MAPI for email.

mlmcc
It is not from the server it is from a workstation where (mostly) Outlook is installed. I need something that opens a new message with the report already attached that the user can complete (to, subject, message).

What I have seen is that CR sends the report/e-mail itself without showing the new message dialog to the user.
I have something working as I want. I have added a button to my report viewer that save my report as a PDF and I use http://www.codeproject.com/KB/IP/SendFileToNET.aspx to open a new Outlook message dialog attaching the PDF automatically.
I have seen this article last night but at that time you were talking to attach file in Outlook express so I rejected it. :S
>>you were talking to attach file in Outlook express

My only comment on OE was that nobody is using it anymore (at least in my users)! I nerver wanted to use it.
>>> I wanted the Outlook (or default e-mail application) window to open a new message window with the report attached.


When you post this comment : ID:33138795 at that time I found this article.
Maybe I don't understand correctly but for me Outlook and Outlook Express are 2 very different products.
May be I could not understand your requirement. But if you got a solution FINE!!!.