cancel
Showing results for 
Search instead for 
Did you mean: 

How to prompt Export-Format-Dialog from Report-Viewer

Former Member
0 Kudos

I'm using .net 2008 and CR 2008 for reporting.

In a form I placed the ReportViewer.

Everything works fine.

Here my problem: When I click "Export" in the Viewer I get the File-Dialog with Excel, Word, PDF.

But I'm missing the dialog where I can choose MAPI (Microsoft Mail) as destination. Like it is possible

at design-time.

To illustrate, how I implemented the CR 2008 in our application:

Public Sub ReportStarten()

Dim l As Integer

Dim Cmd As System.Data.SqlClient.SqlCommand = Nothing

Dim Reader As System.Data.SqlClient.SqlDataReader = Nothing

Dim ReportDataTable As System.Data.DataTable

Dim SqlConn As New System.Data.SqlClient.SqlConnection()

Dim ReportFenster As New ReportForm

If Me._DruckVorschau Then

ReportFenster.Text = Me.Reporttitel

ReportFenster.Show()

ReportFenster.WindowState = Windows.Forms.FormWindowState.Maximized

End If

'Diese Selektion wird im Report selbst berücksichtigt

Me._ReportRpt.DataDefinition.RecordSelectionFormula = Me._RecordSelection

l = 0

Dim myTables As CrystalDecisions.CrystalReports.Engine.Tables = Me._ReportRpt.Database.Tables

For Each myTable As CrystalDecisions.CrystalReports.Engine.Table In myTables

SqlConn.ConnectionString = Me._ConnectionString

SqlConn.Open()

Cmd = New System.Data.SqlClient.SqlCommand(Me._TableSource(l))

Cmd.Connection = SqlConn

Reader = Cmd.ExecuteReader(CommandBehavior.CloseConnection)

ReportDataTable = New System.Data.DataTable()

ReportDataTable.Load(Reader)

myTable.SetDataSource(ReportDataTable)

l += 1

Next

If Me._DruckVorschau Then

'Vorschau

ReportFenster.CrystalReportViewer.ReportSource = Me._ReportRpt

Else

'Sofortdruck

Me._ReportRpt.PrintOptions.PrinterName = Me._DruckerName

Me._ReportRpt.PrintToPrinter(1, False, 0, 0)

'

End If

Accepted Solutions (1)

Accepted Solutions (1)

former_member183750
Active Contributor
0 Kudos

You'll have to code that your self. This will mean your own button and dialog. The actual code for export to mapi would be something like this:

To export to MAPI . You need to export the report to disk and then mail

the exported report as an attachment.

The following example code (written in both Visual

Basic and C#) demonstrates this functionality.

Visual Basic Example

-


'Add the following namespaces

Imports CrystalDecisions.CrystalReports.Engine

Imports CrystalDecisions.Shared

Imports System.IO

' Code for exporting the report to PDF and

' attaching the exported file to an email.

Dim crExportOptions As ExportOptions

Dim crDiskFileDestinationOptions As

DiskFileDestinationOptions

Dim ExportPath As String

' Create an instance of the Report

Dim oRpt As New NameOfYourReport()

' Or open a report file

Dim oRpt1 As New ReportDocument()

oRpt1.Load(Request.PhysicalApplicationPath +

"\YourReport.rpt",

OpenReportMethod.OpenReportByTempCopy)

' Create the directory path if it does not already

' exist

ExportPath = Request.PhysicalApplicationPath +

"Exported\"

If Directory.Exists(ExportPath) = False Then

Directory.CreateDirectory(Request.PhysicalApplicatio

nPath + "Exported\")

End If

Dim fname As String

fname = ExportPath + "Portabledoc.pdf"

' Set the path for the exported report

crDiskFileDestinationOptions = New

DiskFileDestinationOptions()

crDiskFileDestinationOptions.DiskFileName = fname

' Set the options to export the report to PDF format

crExportOptions = oRpt.ExportOptions

With crExportOptions

.DestinationOptions =

crDiskFileDestinationOptions

.ExportDestinationType =

ExportDestinationType.DiskFile

.ExportFormatType =

ExportFormatType.PortableDocFormat

End With

' Export the report

oRpt.Export()

Response.Write("report exported to: " & fname)

' Create a new mail attachment and add the

' exported report

Dim att As New Mail.MailAttachment((fname))

Dim oMsg As New System.Web.Mail.MailMessage()

oMsg.Attachments.Add(att)

' Set the To, From, And subject for the email

oMsg.To = "someonesemail at mail.com" ' use normal email address here (forum will not let me do that)

oMsg.From = "myemail at mail.com " 'ditto

oMsg.Subject = "You have been sent a Crystal Report"

' Connect to the server and send the message

' For example this is the Hotmail smtp Server("")

Mail.SmtpMail.SmtpServer =

"lyris01.hosting.innerhost.com"

System.Web.Mail.SmtpMail.Send(oMsg)

Response.Write("<br>")

Response.Write("Message sent to: " &

oMsg.To.ToString)

' Delete the exported report file

File.Delete(fname)

C# Example

-


// Add the following namespaces

using CrystalDecisions.CrystalReports.Engine;

using CrystalDecisions.Shared;

using System.IO;

// Code for exporting the report to PDF and

// attaching the exported file to an email

ExportOptions crExportOptions;

DiskFileDestinationOptions

crDiskFileDestinationOptions;

String ExportPath;

// Create an instance of the Report

NameOfYourReport oRpt = new NameOfYourReport();

// Or open a report file

ReportDocument oRpt1 = new ReportDocument();

oRpt1.Load(Request.PhysicalApplicationPath +

"
YourReport.rpt",

OpenReportMethod.OpenReportByTempCopy);

// Create the directory path if it does not

// already exist

ExportPath = Request.PhysicalApplicationPath +

"Exported
";

if (Directory.Exists(ExportPath) == false)

{

Directory.CreateDirectory(Request.PhysicalApplicat

ionPath + "Exported
");

}

String fname;

fname = ExportPath + "Portabledoc.pdf";

// Set the path for the exported report

crDiskFileDestinationOptions = new

DiskFileDestinationOptions();

crDiskFileDestinationOptions.DiskFileName = fname;

// Set the options to export the report to PDF

// format

crExportOptions = oRpt.ExportOptions;

crExportOptions.DestinationOptions =

crDiskFileDestinationOptions;

crExportOptions.ExportDestinationType =

ExportDestinationType.DiskFile;

crExportOptions.ExportFormatType =

ExportFormatType.PortableDocFormat;

// Export the report

oRpt.Export();

Response.Write("report exported to: " + fname);

// Create a new mail attachment and add the

// exported report

System.Web.Mail.MailAttachment att = new

System.Web.Mail.MailAttachment((fname));

System.Web.Mail.MailMessage oMsg = new

System.Web.Mail.MailMessage();

oMsg.Attachments.Add(att);

// Set the To, From, And subject for the email

oMsg.To = "someonesemail at email.com"; ' use normal email address here (

oMsg.From = "myemail at email.com "; 'ditto

oMsg.Subject = "You have been sent a Crystal

Report";

// Connect to the server and send the message

// For example this is the Hotmail smtp Server("")

System.Web.Mail.SmtpMail.SmtpServer =

"lyris01.hosting.innerhost.com";

System.Web.Mail.SmtpMail.Send(oMsg);

Response.Write("<br>");

Response.Write("Message sent to: " +

oMsg.To.ToString());

// Delete the exported report file

File.Delete(fname);

Ludek

Answers (1)

Answers (1)

Former Member
0 Kudos

I'm not verry happy, that I have to create the export function for Mapi myself. In the Report-Version 8.0 it was a standard function. But I know now, that I can stop my searching for that non-existing standard feature.