Wrox Programmer Forums
Go Back   Wrox Programmer Forums > .NET > Other .NET > Crystal Reports
| Search | Today's Posts | Mark Forums Read
Crystal Reports General discussion about Crystal Reports. For discussions specific to the book Professional Crystal Reports for VS.NET, please see the book discussion forum for that book.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Crystal Reports section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old October 31st, 2006, 09:50 AM
Registered User
 
Join Date: Oct 2006
Location: , , .
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Default Exporting Crystal Reports to PDF using ASP.NET

Hi there,

I have created a crystal report in Visual Studio 2005 which retrieves it's information from an SQL Server 2000 Table. VS has automatically generated the following ASP.NET page to display the report for me:

Code:
<%@ Page Language="VB" AutoEventWireup="false" CodeFile="CostDetailsReport.aspx.vb" Inherits="_Default" %>
<%@ Register TagPrefix="CR" Namespace="CrystalDecisions.Web" Assembly="CrystalDecisions.Web, Version=10.2.3600.0, Culture=neutral, PublicKeyToken=692fbea5521e1304" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title>Cost Details</title>
</head>
<body>

    <form id="form1" runat="server">
    <div>
        <CR:CrystalReportViewer ID="CrystalReportViewer1" Runat="server" AutoDataBind="True"
            Height="947px" ReportSourceID="CrystalReportSource1" Width="845px" />
        <CR:CrystalReportSource ID="CrystalReportSource1" runat="server">
            <Report FileName="CostDetailsReport.rpt">
            </Report>

        </CR:CrystalReportSource>

    </div>

    </form>
</body>
</html>

Here's the issue:

Instead of loading and displaying the report inside the Crystal Report Viewer of a browser window, I would like to export it straight into a PDF document and display that instead. I have seen a few code examples but I am not particularly familier with ASP.NET so I don't know how to implement them inside the page. Could anyone suggest a way of doing this? Or maybe even some code?

Thanks in advance for any help! =S
 
Old November 22nd, 2006, 12:47 AM
Registered User
 
Join Date: Nov 2006
Location: Moradabad, UP, India.
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Yahoo to kkgaurav1983
Default

try it by changing accordingly

Dim str_L_Sql As String
        Dim dr As SqlDataReader
        Dim cmd As New SqlCommand
        Dim conn As New SqlConnection(strCon)
        Dim oStream As New MemoryStream
        Dim DiskOutPut As New DiskFileDestinationOptions
        lblExport.Text = ""

        Try
            crReportDocument.Load(CStr(Session("RepPath") & str_P_ReportName))
            Dim expOpt As New ExportOptions(crReportDocument.ExportOptions)
            MISCRViewer.ReportSource = Nothing

            With crconnectioninfo
                .ServerName = Session("SName")
                .DatabaseName = Session("DBName")
                .UserID = Session("Uid")
                .Password = Session("Pwd")
            End With


            crtables = crReportDocument.Database.Tables


            For Each crtable In crtables
                crtablelogoninfo = crtable.LogOnInfo
                crtablelogoninfo.ConnectionInfo = crconnectioninfo
                crtable.ApplyLogOnInfo(crtablelogoninfo)
            Next

            MISCRViewer.ReportSource = crReportDocument
            MISCRViewer.RefreshReport()

            str_L_Sql = "Select param_Name,orderNo from tbl_Report_D where report_ID=(Select report_ID from tbl_Report_M where report_Name='" & str_P_ReportName & "') order by orderNo"

            conn.Open()
            With cmd
                .CommandType = CommandType.Text
                .CommandText = str_L_Sql
                .Connection = conn
            End With

            dr = cmd.ExecuteReader()

            While dr.Read()
                If CStr(Session(dr.Item(0).ToString)) <> "" Then
                    crParameterFields = MISCRViewer.ParameterFieldInfo
                    crParameterField = crParameterFields.Item(CInt(dr.Item(1).ToString) - 1)
                    crParameterValues = crParameterField.CurrentValues
                    crParameterDiscreteValue = New ParameterDiscreteValue()
                    crParameterDiscreteValue.Value = Session(dr.Item(0).ToString)
                    crParameterValues.Add(crParameterDiscreteValue)
                End If
            End While

            dr.Close()
            MISCRViewer.ParameterFieldInfo = crParameterFields

            Select Case cboExportType.SelectedItem.Text
                Case "Rich Text (RTF)"
                    expOpt.ExportFormatType = ExportFormatType.RichText
                    DiskOutPut.DiskFileName = "C:\Inetpub\wwwroot\Calm_website\GlobalScheme. rtf"
                Case "Portable Document (PDF)"
                    expOpt.ExportFormatType = ExportFormatType.PortableDocFormat
                    DiskOutPut.DiskFileName = "C:\Inetpub\wwwroot\Calm_website\GlobalScheme. pdf"
                Case "MS Word (DOC)"
                    expOpt.ExportFormatType = ExportFormatType.WordForWindows
                    DiskOutPut.DiskFileName = "C:\Inetpub\wwwroot\Calm_website\GlobalScheme. doc"
                Case "MS Excel (XLS)"
                    expOpt.ExportFormatType = ExportFormatType.Excel
                    DiskOutPut.DiskFileName = "C:\Inetpub\wwwroot\Calm_website\GlobalScheme. xls"
            End Select
            expOpt.ExportDestinationType = ExportDestinationType.DiskFile
            expOpt.DestinationOptions = DiskOutPut
            crReportDocument.Export()
            lblExport.Text = "Exported to the Destination Successfully!"
        Catch err As Exception
            lblExport.Text = err.Message & "Error in Exporting!"
        Finally
            conn.Close()
            cmd = Nothing
        End Try
    End Sub

KK GAURAV
RELIGARE SECURITIES LTD
 
Old November 22nd, 2006, 12:53 AM
Registered User
 
Join Date: Nov 2006
Location: Moradabad, UP, India.
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Yahoo to kkgaurav1983
Default

dear its all and everything dyanamic.this crystal report is prepared using stored procedure so I have to pass parameters.and after logging in database givening username and password i can directly import it in any format selected by list.In case of access database no need for database login


KK GAURAV
RELIGARE SECURITIES LTD




Similar Threads
Thread Thread Starter Forum Replies Last Post
Problem in saving PDF from crystal reports in asp r.surendhar Classic ASP Components 1 January 22nd, 2007 06:21 AM
exporting crystal reports through vb.net nikks9 Crystal Reports 0 May 16th, 2006 04:16 AM
Logon failed... exporting crystal reports into pdf JerBlur VB.NET 0 July 23rd, 2004 02:00 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.