Writing Code
 Crystal Reports Forum : Crystal Reports for Visual Studio 2005 and Newer : Writing Code
Message Icon Topic: Export error message Post Reply Post New Topic
Author Message
chitemerere
Newbie
Newbie
Avatar

Joined: 04 Jul 2008
Location: Zimbabwe
Online Status: Offline
Posts: 29
Quote chitemerere Replybullet Topic: Export error message
    Posted: 05 Feb 2009 at 7:55am
Dear Brian
 
When I run the book chapter 19 of the new book code for exporting to EMail, I get the following exception:
 
CrystalDecisions.CrystalReports.Engine.InvalidArgumentException was unhandled
  Message="Invalid export options."
  Source="CrystalDecisions.CrystalReports.Engine"
  StackTrace:
       at CrystalDecisions.CrystalReports.Engine.STACaller.Call()    at CrystalDecisions.CrystalReports.Engine.MAPIMessage.Send()    at CrystalDecisions.CrystalReports.Engine.FormatEngine.ExportStreamToMAPI(Stream stream, MicrosoftMailDestinationOptions options, String name)    at CrystalDecisions.CrystalReports.Engine.FormatEngine.Export(ExportRequestContext reqContext)    at CrystalDecisions.CrystalReports.Engine.ReportDocument.Export(ExportOptions options)    at _19_Exporting.Form1.ExportToEmail(ReportDocument myReport, String MailTo, String CCList, String Subject, String Message, String UserName, String Password) in C:\Users\Chitemerere\Documents\Crystal Reports\Brian Bishoff\CRNET 2005 Book\Windows\VB\19 Exporting\19 Exporting\Form1.vb:line 103    at _19_Exporting.Form1.Form1_Load(Object sender, EventArgs e) in C:\Users\Chitemerere\Documents\Crystal Reports\Brian Bishoff\CRNET 2005 Book\Windows\VB\19 Exporting\19 Exporting\Form1.vb:line 9    at System.EventHandler.Invoke(Object sender, EventArgs e)    at System.Windows.Forms.Form.OnLoad(EventArgs e)    at System.Windows.Forms.Form.OnCreateControl()    at System.Windows.Forms.Control.CreateControl(Boolean fIgnoreVisible)    at System.Windows.Forms.Control.CreateControl()    at System.Windows.Forms.Control.WmShowWindow(Message& m)    at System.Windows.Forms.Control.WndProc(Message& m)    at System.Windows.Forms.ScrollableControl.WndProc(Message& m)    at System.Windows.Forms.ContainerControl.WndProc(Message& m)    at System.Windows.Forms.Form.WmShowWindow(Message& m)    at System.Windows.Forms.Form.WndProc(Message& m)    at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)    at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)    at System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)    at System.Windows.Forms.SafeNativeMethods.ShowWindow(HandleRef hWnd, Int32 nCmdShow)    at System.Windows.Forms.Control.SetVisibleCore(Boolean value)    at System.Windows.Forms.Form.SetVisibleCore(Boolean value)    at System.Windows.Forms.Control.set_Visible(Boolean value)    at System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)    at System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)    at System.Windows.Forms.Application.Run(ApplicationContext context)    at Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.OnRun()    at Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.DoApplicationModel()    at Microsoft.VisualBasic.ApplicationServices.WindowsFormsApplicationBase.Run(String[] commandLine)    at _19_Exporting.My.MyApplication.Main(String[] Args) in 17d14f5c-a337-4978-8281-53493378c1071.vb:line 81    at System.AppDomain._nExecuteAssembly(Assembly assembly, String[] args)    at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)    at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()    at System.Threading.ThreadHelper.ThreadStart_Context(Object state)    at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)    at System.Threading.ThreadHelper.ThreadStart()
  InnerException:
The code breaks at the line:  myReport.Export(myExportOptions)
 
what could be the problem and what is the solution?
 
Many thanks.
Chris
IP IP Logged
BrianBischof
Admin Group
Admin Group
Avatar

Joined: 09 Nov 2006
Online Status: Offline
Posts: 2458
Quote BrianBischof Replybullet Posted: 05 Feb 2009 at 11:40am
Can you post your code? All the code listings in the book are from sample apps that I built and all were tested prior to copying the code over.
Please support the forum! Tell others by linking to it on your blog or website:<a href="http://www.crystalreportsbook.com/forum/">Crystal Reports Forum</a>
IP IP Logged
chitemerere
Newbie
Newbie
Avatar

Joined: 04 Jul 2008
Location: Zimbabwe
Online Status: Offline
Posts: 29
Quote chitemerere Replybullet Posted: 06 Feb 2009 at 2:10am
I have realiazide that the code only works when your mail program, Microsoft Outlook is open.  If it is not, that is when you get an exception.  Should this be the case, i.e. you have to have your mail program open before you run the export code?  But however, the file exported to my mail program is not a pdf but a text file which is unreadable.
 
Please find below the code i am using.
 

Public Class Form1

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

Dim myReport As New CrystalDecisions.CrystalReports.Engine.ReportDocument

myReport.Load("..\..\Grouping.rpt")

'ExportToPdfRtfWord("Grouping.doc", myReport, False, 0, 0)

'ExportToExcel("Grouping.xls", myReport, False, 0, True)

'ExportToHTML("Crystal Html Files", "Employees", myReport, True, True)

ExportToEmail(myReport, "crimbo@ecoweb.co.zw", "", "testing", "See if this works", "crimbo", "Hd82vp")

'ExportToExchange(myReport, "kdkd", "a", "b")

End Sub

Public Sub ExportToPdfRtfWord(ByVal Filename As String, ByRef myReport As CrystalDecisions.CrystalReports.Engine.ReportDocument, ByVal UsePageRange As Boolean, ByVal FirstPageNumber As Integer, ByVal LastPageNumber As Integer)

Dim myExportOptions As New CrystalDecisions.Shared.ExportOptions

'Set the export to a disk file

myExportOptions.ExportDestinationType = CrystalDecisions.Shared.ExportDestinationType.DiskFile

Dim myDestinationOptions As CrystalDecisions.Shared.DiskFileDestinationOptions

myDestinationOptions = CrystalDecisions.Shared.ExportOptions.CreateDiskFileDestinationOptions

myDestinationOptions.DiskFileName = Filename

myExportOptions.ExportDestinationOptions = myDestinationOptions

'Change the next line if you want the format to be RTF or Word

myExportOptions.ExportFormatType = CrystalDecisions.Shared.ExportFormatType.WordForWindows

'The following lines stay the same regardless of formatting

Dim myFormatOptions As CrystalDecisions.Shared.PdfRtfWordFormatOptions

myFormatOptions = CrystalDecisions.Shared.ExportOptions.CreatePdfRtfWordFormatOptions()

myFormatOptions.UsePageRange = UsePageRange

If UsePageRange Then

myFormatOptions.FirstPageNumber = FirstPageNumber

myFormatOptions.LastPageNumber = LastPageNumber

End If

'Assign the formatting properties to the report and export it

myExportOptions.FormatOptions = myFormatOptions

myReport.Export(myExportOptions)

End Sub

Public Sub ExportToExcel(ByVal Filename As String, ByRef myReport As CrystalDecisions.CrystalReports.Engine.ReportDocument, ByVal UseConstantColumnWidth As Boolean, ByVal ColumnWidth As Integer, ByVal UseColumnHeadings As Boolean)

Dim myExportOptions As New CrystalDecisions.Shared.ExportOptions

'Set the export to a disk file

myExportOptions.ExportDestinationType = CrystalDecisions.Shared.ExportDestinationType.DiskFile

Dim myDestinationOptions As CrystalDecisions.Shared.DiskFileDestinationOptions

myDestinationOptions = CrystalDecisions.Shared.ExportOptions.CreateDiskFileDestinationOptions

myDestinationOptions.DiskFileName = Filename

myExportOptions.ExportDestinationOptions = myDestinationOptions

'Set the Excel formatting properties

myExportOptions.ExportFormatType = CrystalDecisions.Shared.ExportFormatType.ExcelRecord

Dim myFormatOptions As CrystalDecisions.Shared.ExcelFormatOptions

myFormatOptions = CrystalDecisions.Shared.ExportOptions.CreateExcelFormatOptions()

myFormatOptions.ExcelConstantColumnWidth = ColumnWidth

myFormatOptions.ExcelUseConstantColumnWidth = UseConstantColumnWidth

myFormatOptions.ExcelTabHasColumnHeadings = UseColumnHeadings

'Assign the formatting properties to the report and export it

myExportOptions.FormatOptions = myFormatOptions

myReport.Export(myExportOptions)

End Sub

Public Sub ExportToHTML(ByVal HTMLBaseFolderName As String, ByVal Filename As String, ByRef myReport As CrystalDecisions.CrystalReports.Engine.ReportDocument, ByVal EnableSeparatedPages As Boolean, ByVal HasPageNavigator As Boolean)

Dim myExportOptions As New CrystalDecisions.Shared.ExportOptions

'Set HTML specific formatting properties

myExportOptions.ExportFormatType = CrystalDecisions.Shared.ExportFormatType.HTML40

Dim myOptions As CrystalDecisions.Shared.HTMLFormatOptions

myOptions = CrystalDecisions.Shared.ExportOptions.CreateHTMLFormatOptions()

myOptions.HTMLBaseFolderName = HTMLBaseFolderName

myOptions.HTMLFileName = Filename

myOptions.HTMLHasPageNavigator = HasPageNavigator

myOptions.HTMLEnableSeparatedPages = EnableSeparatedPages

'Assign the formatting properties to the report and export it

myExportOptions.FormatOptions = myOptions

myReport.Export(myExportOptions)

End Sub

Public Sub ExportToExchange(ByVal myReport As CrystalDecisions.CrystalReports.Engine.ReportDocument, ByVal FolderPath As String, ByVal Password As String, ByVal Profile As String)

'Set the destination type to ExchangeFolder

Dim myExportOptions As New CrystalDecisions.Shared.ExportOptions

myExportOptions.ExportDestinationType = CrystalDecisions.Shared.ExportDestinationType.ExchangeFolder

myExportOptions.ExportFormatType = CrystalDecisions.Shared.ExportFormatType.PortableDocFormat

'Instantiate an ExchangeFolder options object and set its properties

Dim myOptions As CrystalDecisions.Shared.ExchangeFolderDestinationOptions

myOptions = CrystalDecisions.Shared.ExportOptions.CreateExchangeFolderDestinationOptions()

myOptions.DestinationType = CrystalDecisions.Shared.ExchangeDestinationType.ExchangePostDocMessage

myOptions.FolderPath = FolderPath

myOptions.Password = Password

myOptions.Profile = Profile

myExportOptions.DestinationOptions = myOptions

myReport.Export(myExportOptions)

End Sub

Public Sub ExportToEmail(ByVal myReport As CrystalDecisions.CrystalReports.Engine.ReportDocument, ByVal MailTo As String, ByVal CCList As String, ByVal Subject As String, ByVal Message As String, ByVal UserName As String, ByVal Password As String)

'Set the destination type to Email

Dim myExportOptions As New CrystalDecisions.Shared.ExportOptions

myExportOptions.ExportDestinationType = CrystalDecisions.Shared.ExportDestinationType.MicrosoftMail

myExportOptions.ExportFormatType = CrystalDecisions.Shared.ExportFormatType.PortableDocFormat

'Instantiate an Email options object and set its properties

Dim myOptions As CrystalDecisions.Shared.MicrosoftMailDestinationOptions

myOptions = CrystalDecisions.Shared.ExportOptions.CreateMicrosoftMailDestinationOptions()

myOptions.UserName = "crimbo"

myOptions.Password = "Hd82vp"

myOptions.MailSubject = "Testing"

myOptions.MailMessage = "See if this works"

myOptions.MailToList = "crimbo@ecoweb.co.zw"

myOptions.MailCCList = ""

'Assign the options object to the report

myExportOptions.DestinationOptions = myOptions

myReport.Export(myExportOptions)

End Sub

End Class

Chris
IP IP Logged
chitemerere
Newbie
Newbie
Avatar

Joined: 04 Jul 2008
Location: Zimbabwe
Online Status: Offline
Posts: 29
Quote chitemerere Replybullet Posted: 06 Feb 2009 at 7:59am

Dear Brian

Further to my last post, I find it strange, I ran the Chapter 19 code without may mail program being open and it worked with no exception messages!!! However, the chapter 19 report is attached as a txt document and when you open it, it is ureadable.  What is going wrong?

Many thanks

Chris

 

 

 

Chris
IP IP Logged
Post Reply Post New Topic
Printable version Printable version

Forum Jump
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot delete your posts in this forum
You cannot edit your posts in this forum
You cannot create polls in this forum
You cannot vote in polls in this forum



This page was generated in 0.016 seconds.