Solved

Export to PDF fails using ASP.NET

Posted on 2004-04-01
7
3,230 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
7 Comments
 
LVL 100

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: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering 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 100

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 500 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

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.

Question has a verified solution.

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

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…
Hot fix for .Net Crystal Reports 10.2.3600.0 to fix problems with sub reports running on 64 bit operating systems ISSUE: Reports which contain subreports fail with error "Missing Parameter Value" DEPLOYMENT SERVER OS: Windows 2008 with 64 bi…
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…
This video shows how to use Hyena, from SystemTools Software, to update 100 user accounts from an external text file. View in 1080p for best video quality.

752 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