Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Export to PDF fails using ASP.NET

Posted on 2004-04-01
7
Medium Priority
?
3,289 Views
Last Modified: 2007-12-19
I made a report based on an SP and it works great (VS 2003). Using code, I run the query and then export it to a PDF. I then made a second report, copying the code from the working page, but now I get an error on the export.

I am pulling my hair out (and I don't have that much to spare. I don't know where to begin, or what code to post.

Please help me!
0
Comment
Question by:jawhitmoyer
7 Comments
 
LVL 101

Expert Comment

by:mlmcc
ID: 10734360
What error are you getting?

Post the code for the new report.

mlmcc
0
 
LVL 42

Expert Comment

by:frodoman
ID: 10734378
What is the error message?
0
 

Author Comment

by:jawhitmoyer
ID: 10734510
Here's the code:

    Sub BindReport()

        Dim myConnection As New SqlClient.SqlConnection

        myConnection.ConnectionString = "server=sql01;" _
                                            & "Initial Catalog=forensicsSQL;" _
                                            & "User Id=sa;" _
                                            & "Password=token!;"

        Dim MyCommand As New SqlClient.SqlCommand

        MyCommand.Connection = myConnection
        MyCommand.CommandType = CommandType.Text
        MyCommand.CommandText = "select * from user_photoReportTemp"

        Dim MyDA As New SqlClient.SqlDataAdapter

        MyDA.SelectCommand = MyCommand

        Dim myDS As New Dataset4

        MyDA.Fill(myDS, "user_rptCaseDocList")

        Dim oRpt As New PhotoReport2

        oRpt.SetDataSource(myDS)

        Dim DiskOpts As CrystalDecisions.Shared.DiskFileDestinationOptions = New CrystalDecisions.Shared.DiskFileDestinationOptions

        oRpt.ExportOptions.ExportDestinationType = CrystalDecisions.[Shared].ExportDestinationType.DiskFile

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

        DiskOpts.DiskFileName = "C:\Inetpub\wwwroot\SQLaspx\PhotoReport.pdf"

        oRpt.ExportOptions.DestinationOptions = DiskOpts

        oRpt.Export()

        myDS = Nothing
        myConnection.Close()
        Response.Redirect("./PhotoReport.pdf")
    End Sub

The error:

Server Error in '/SQLASPX' Application.
--------------------------------------------------------------------------------

Error in File C:\DOCUME~1\JAWHIT~1\ASPNET\LOCALS~1\Temp\temp_d34488ef-ebdf-417d-9ce7-07ab9608c65f.rpt: Error detected by export DLL:
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.ExportException: Error in File C:\DOCUME~1\JAWHIT~1\ASPNET\LOCALS~1\Temp\temp_d34488ef-ebdf-417d-9ce7-07ab9608c65f.rpt: Error detected by export DLL:

Source Error:


Line 173:        oRpt.ExportOptions.DestinationOptions = DiskOpts
Line 174:
Line 175:        oRpt.Export()
Line 176:
Line 177:        myDS = Nothing
 

Source File: C:\Inetpub\wwwroot\SQLaspx\photoReport.aspx.vb    Line: 175
0
Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 

Author Comment

by:jawhitmoyer
ID: 10734542
Oh yeah, the report is bound to the Dataset4 I created off the table.
0
 

Author Comment

by:jawhitmoyer
ID: 10734577
I am continuing to test, so please consider these points.

There is am image in the table, which I need to display. I just tried deleting the image field, and it did the export, but there was not other data...just the report form.
0
 
LVL 101

Expert Comment

by:mlmcc
ID: 10737690
As a guess, i don't have CR.Net so I can't verify.  Does CR.Net support loading pictures from a datasource?  I think that is one of the features not in the .Net versions.

Not sure about the ASP but I have seen other code where instead of a new they used the one for the report
Try changing
Dim DiskOpts As CrystalDecisions.Shared.DiskFileDestinationOptions = New CrystalDecisions.Shared.DiskFileDestinationOptions

to
Dim DiskOpts As CrystalDecisions.Shared.DiskFileDestinationOptions
DiskOpts = oRpt.ExportOptions.DestinationOptions

mlmcc
0
 
LVL 4

Accepted Solution

by:
kssaran earned 2000 total points
ID: 10738452
You can Try Exporting to PDF File as mentioned Bellow


   'Variable initialised at the class level
    Dim strInvoiceNo As String
    Dim strSelectFormula As String
    Dim ServerName As String, UserId As String, Password As String

    Private Sub cmdShowReport_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdShowReport.Click
        ExportReport("servername", "username", "password")
    End Sub



    Private Sub ExportReport(ByVal ServerName As String, ByVal UserId As String, ByVal Password As String)
    'To Export the Result into a PDF File and display the Same in the window
        Dim myReport As New SampleReport()
        strInvoiceNo = Request.Form("txtInvoiceNo")
        strSelectFormula = "{invoice_header.inh_invoiceno} = '" + strInvoiceNo + "'"
        myReport.RecordSelectionFormula = strSelectFormula
        'Set the logon credentials of the main report
        LogonToDatabase(myReport.Database.Tables, ServerName, UserId, Password)

        'Modify the sub-report properties

        Dim mySection As CrystalDecisions.CrystalReports.Engine.Section
        Dim myReportObject As CrystalDecisions.CrystalReports.Engine.ReportObject
        Dim mySubReport As CrystalDecisions.CrystalReports.Engine.SubreportObject
        Dim mySubReportDoc As CrystalDecisions.CrystalReports.Engine.ReportDocument

        'Loop through each section of the main report

        For Each mySection In myReport.ReportDefinition.Sections
            'Drill down into the section to see if there are any sub-reports
            For Each myReportObject In mySection.ReportObjects
                If myReportObject.Kind = _
                    CrystalDecisions.[Shared].ReportObjectKind.SubreportObject Then
                    mySubReport = CType(myReportObject, _
                        CrystalDecisions.CrystalReports.Engine.SubreportObject)

                    'Get a reference to the sub-report object
                    'so we can change its properties
                    mySubReportDoc = mySubReport.OpenSubreport(mySubReport.SubreportName)
                    'Set the logon credentials
                    LogonToDatabase(mySubReportDoc.Database.Tables, ServerName, UserId, Password)
                End If
            Next
        Next
        Dim myExportExt As String, myExportType As String, myExportFile As String
        Dim strExportType As String
        strExportType = "PDF"

        If strExportType = UCase("Excel") Then
            myExportExt = ".xls"
            myExportType = "application/vnd.ms-excel"
        ElseIf strExportType = UCase("HTML") Then
            myExportExt = ".html"
            myExportType = "application/html"
        ElseIf strExportType = UCase("PDF") Then
            myExportExt = ".pdf"
            myExportType = "application/pdf"
        ElseIf strExportType = UCase("RichText") Then
            myExportExt = ".rtf"
            myExportType = "application/rtf"
        ElseIf strExportType = UCase("Word") Then
            myExportExt = ".doc"
            myExportType = "application/msword"
        End If

        Dim myExportOptions As CrystalDecisions.Shared.ExportOptions
        Dim myDiskFileDestinationOptions As CrystalDecisions.Shared.DiskFileDestinationOptions

        'myExportFile = Server.MapPath(".") & "\" & Session.SessionID.ToString & myExportExt
        myExportFile = "c:\winnt\temp\" & Session.SessionID.ToString & myExportExt

        myDiskFileDestinationOptions = New CrystalDecisions.Shared.DiskFileDestinationOptions()
        myDiskFileDestinationOptions.DiskFileName = myExportFile
        myExportOptions = myReport.ExportOptions

        With myExportOptions

            .DestinationOptions = myDiskFileDestinationOptions
            .ExportDestinationType = .ExportDestinationType.DiskFile

            If strExportType = UCase("Excel") Then
                .ExportFormatType = .ExportFormatType.Excel
            ElseIf strExportType = UCase("HTML") Then
                .ExportFormatType = .ExportFormatType.HTML40
            ElseIf strExportType = UCase("PDF") Then
                .ExportFormatType = .ExportFormatType.PortableDocFormat
            ElseIf strExportType = UCase("RichText") Then
                .ExportFormatType = .ExportFormatType.RichText
            ElseIf strExportType = UCase("Word") Then
                .ExportFormatType = .ExportFormatType.WordForWindows
            End If
        End With

        'Exports the report to PDF format
        myReport.Export()
        Response.ClearContent()
        Response.ClearHeaders()
        Response.ContentType = myExportType
        Response.WriteFile(myExportFile)
        Response.Flush()
        Response.Close()

        System.IO.File.Delete(myExportFile)
    End Sub

    Private Sub LogonToDatabase(ByVal ReportTables As CrystalDecisions.CrystalReports.Engine.Tables, ByVal ServerName As String, ByVal UserId As String, ByVal Password As String)
    ' To Supply Logon Information to each and every Tables used in the Report
        Dim myTable As CrystalDecisions.CrystalReports.Engine.Table
        Dim myConnectionInfo As New CrystalDecisions.Shared.ConnectionInfo()
        Dim myLogonInfo As New CrystalDecisions.Shared.TableLogOnInfo()
        myConnectionInfo.UserID = UserId
        myConnectionInfo.Password = Password
        myConnectionInfo.ServerName = ServerName
        myLogonInfo.ConnectionInfo = myConnectionInfo
        For Each myTable In ReportTables
            myTable.ApplyLogOnInfo(myLogonInfo)
        Next
    End Sub
0

Featured Post

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Crystal Reports: 5 Tests for Top Performance It is complete, your masterpiece report.  Not only does it meet your customer’s expectations, it blows them out the water, all they want is beautifully summarised and displayed in a myriad of ways. …
I hate sub reports and always consider them the last resort in any reporting solution.  The negative effect on performance and maintainability is just not worth the easy ride they give the report writer.  Nine times out of ten reporting requirements…
This Micro Tutorial will teach you how to add a cinematic look to any film or video out there. There are very few simple steps that you will follow to do so. This will be demonstrated using Adobe Premiere Pro CS6.
In response to a need for security and privacy, and to continue fostering an environment members can turn to for support, solutions, and education, Experts Exchange has created anonymous question capabilities. This new feature is available to our Pr…

971 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question