Results 1 to 2 of 2

Thread: RESOLVED!! How to export to PDF for printing using VS.NET

  1. #1

    Thread Starter
    Hyperactive Member ARPRINCE's Avatar
    Join Date
    Mar 2003
    Location
    Pinoy in NJ
    Posts
    381

    Question RESOLVED!! How to export to PDF for printing using VS.NET

    Has anyone successfully configured export to PDF for printing using VS and CR on a web? I'm having problems with my code. It craps out when I reach export command.

    I'm getting the error:

    Invalid export options.
    Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

    Exception Details: CrystalDecisions.CrystalReports.Engine.InvalidArgumentException: Invalid export options.

    Source Error:


    Line 286: '| EXPORT |
    Line 287: '+--------+
    Line 288: crReportDocument1.Export() '<---- ERROR HERE
    Line 289:
    Line 290: '+-----------------+


    Source File: c:\inetpub\wwwroot\CRTEST\RAInformation_ORIG.aspx.vb Line: 288

    Stack Trace:


    [InvalidArgumentException: Invalid export options.]
    .L(String , EngineExceptionErrorID )
    .H(String , Int32 )
    CrystalDecisions.CrystalReports.Engine.FormatEngine.internalSetExportOptions(ExportOptions exportOptions)
    CrystalDecisions.CrystalReports.Engine.FormatEngine.Export(ExportRequestContext reqContext)
    CrystalDecisions.CrystalReports.Engine.FormatEngine.Export()
    CrystalDecisions.CrystalReports.Engine.ReportDocument.Export()
    CRTEST.RAInformation_ORIG1.Button1_Click(Object sender, EventArgs e) in c:\inetpub\wwwroot\CRTEST\RAInformation_ORIG.aspx.vb:288
    System.Web.UI.WebControls.Button.OnClick(EventArgs e)
    System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument)
    System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument)
    System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData)
    System.Web.UI.Page.ProcessRequestMain()




    VB Code:
    1. Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    2.  
    3.         Dim crReportDocument1 As ReportDocument
    4.         Dim crExportOptions As ExportOptions
    5.         Dim crDiskFileDestinationOptions As DiskFileDestinationOptions
    6.  
    7.         '+-------------------------+
    8.         '| CREATE NAME OF PDF FILE |
    9.         '+-------------------------+
    10.         Dim Fname As String
    11.         Fname = "C:\EXPORTS\" & Session.SessionID.ToString & ".pdf"
    12.  
    13.         '+--------------------------+
    14.         '| INITIALIZE REPORT OBJECT |
    15.         '+--------------------------+
    16.         crReportDocument1 = New ReportDocument
    17.         crReportDocument1.Load("C:\inetpub\wwwroot\CRTEST\RAInformation_ORIG.RPT")
    18.  
    19.         '+-----------------+
    20.         '| SQL SERVER INFO |
    21.         '+-----------------+
    22.         crConnectionInfo = New ConnectionInfo
    23.         With crConnectionInfo
    24.             .ServerName = "SQLMAIN"
    25.             .DatabaseName = "RMA"
    26.             .UserID = "USER1"
    27.             .Password = "TESTDATA"
    28.         End With
    29.  
    30.         '+------------------------------------------+
    31.         '| GET TABLES COLLECTION FROM REPORT OBJECT |
    32.         '+------------------------------------------+
    33.         crDatabase = crReportDocument1.Database
    34.         crTables = crDatabase.Tables
    35.  
    36.         '+-------------------------+
    37.         '| APPLY LOGIN INFORMATION |
    38.         '+-------------------------+
    39.         For Each crTable In crTables
    40.             crTableLogOnInfo = crTable.LogOnInfo
    41.             crTableLogOnInfo.ConnectionInfo = crConnectionInfo
    42.             crTable.ApplyLogOnInfo(crTableLogOnInfo)
    43.         Next
    44.  
    45.         '+---------------------------+
    46.         '| INITIALIZE EXPORT OPTIONS |
    47.         '+---------------------------+
    48.         crDiskFileDestinationOptions = New DiskFileDestinationOptions
    49.         crDiskFileDestinationOptions.DiskFileName = Fname
    50.         crExportOptions = crReportDocument1.ExportOptions
    51.  
    52.  
    53.         '+------------------------------------------------+
    54.         '| INITILIZE PARAMETER FIELD AND VALUE COLLECTION |
    55.         '+------------------------------------------------+
    56.         Dim crParamFields As ParameterFieldDefinitions = crReportDocument1.DataDefinition.ParameterFields
    57.         Dim crParamField As ParameterFieldDefinition                                                ' Crystal Parameter Field
    58.         Dim crParamValues As ParameterValues                                                        ' Crystal Parameter Values Collection
    59.         Dim crParamValue As ParameterDiscreteValue                                                  ' Crystal Parameter Value
    60.  
    61.         '+---------------------+
    62.         '| SET PARAMETER VALUE |
    63.         '+---------------------+
    64.         crParamField = crParamFields(0)               ' Get Parameter Field
    65.         crParamValues = crParamField.CurrentValues              ' Get Current Values
    66.         crParamValue = New ParameterDiscreteValue               ' Instanciate New Discrete Value
    67.         crParamValue.Value = "16040050"                         ' Set Discrete Value
    68.         crParamValues.Add(crParamValue)                         ' Add Value to CurrentValues Collection
    69.         crParamField.ApplyCurrentValues(crParamValues)          ' Apply Value Changes
    70.  
    71.  
    72.         With crExportOptions
    73.             .DestinationOptions = crDiskFileDestinationOptions
    74.             .DestinationOptions = .ExportDestinationType.DiskFile
    75.             .ExportFormatType = .ExportFormatType.PortableDocFormat
    76.         End With
    77.  
    78.  
    79.         '+--------+
    80.         '| EXPORT |
    81.         '+--------+
    82.         crReportDocument1.Export()       '<---- ERROR HERE
    83.  
    84.         '+-----------------+
    85.         '| SEND TO BROWSER |
    86.         '+-----------------+
    87.         Response.ClearContent()
    88.         Response.ClearHeaders()
    89.         Response.ContentType = "application/pdf"
    90.         Response.WriteFile(Fname)
    91.  
    92.         '+---------+
    93.         '| CLEANUP |
    94.         '+---------+
    95.         Response.Flush()
    96.         Response.Close()
    97.  
    98.         System.IO.File.Delete(Fname)
    99.     End Sub


    TIF
    Last edited by ARPRINCE; Mar 29th, 2004 at 03:33 PM.

  2. #2

    Thread Starter
    Hyperactive Member ARPRINCE's Avatar
    Join Date
    Mar 2003
    Location
    Pinoy in NJ
    Posts
    381
    OK here's the culprit!

    VB Code:
    1. With crExportOptions
    2.             .DestinationOptions = crDiskFileDestinationOptions
    3.             '.DestinationOptions = .ExportDestinationType.DiskFile.ExportFormatType    <---- WRONG OPTION
    4.             .ExportDestinationType = .ExportDestinationType.DiskFile
    5.             .ExportFormatType = .ExportFormatType.PortableDocFormat
    6.         End With

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width