3
Contributors
2
Replies
3
Views
7 Years
Discussion Span
Last Post by pauldani
0

Hi..

I try to help u

Dim FileName As String = ""
    Dim ErrorMessage As String
    Dim ExportToExcel As String = "0" 
    Dim Folder As String = ""

  Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        If Not Request.QueryString("ExportToExcel") Is Nothing Then ExportToExcel = Request.QueryString("ExportToExcel")
        If Not Request.QueryString("DataOnly") Is Nothing Then DataOnly = Request.QueryString("DataOnly")
        If Not Request.QueryString("folder") Is Nothing Then Folder = Request.QueryString("folder").Trim

        FileName = Request.QueryString("FileName")
        If FileName = "" Then Response.Redirect("../Others/Sorry.aspx?ErrorMessage=File is not found !")
        If Not IsPostBack Then
             ConfigureCrsytalReports()
            ExportReport()
        End If
    End Sub

 Sub SetDBLogonForReport()
        Dim Table As CrystalDecisions.CrystalReports.Engine.Table
        For Each Table In Crs.ReportDocument.Database.Tables
            Dim Logon As CrystalDecisions.Shared.TableLogOnInfo
            Logon = Table.LogOnInfo
            Logon.ConnectionInfo.ServerName = ConfigurationManager.AppSettings("Server").Trim
            Logon.ConnectionInfo.DatabaseName = ConfigurationManager.AppSettings("Database").Trim
            Logon.ConnectionInfo.Password = ConfigurationManager.AppSettings("Password").Trim 'Security.Decryp_Pwd(ConfigurationManager.AppSettings("Password").Trim)
            Logon.ConnectionInfo.UserID = ConfigurationManager.AppSettings("UID").Trim
            Table.ApplyLogOnInfo(Logon)
        Next
    End Sub

 Sub ExportReport()
        Dim WebMainFolder As String = Request.PhysicalApplicationPath
        Dim PdfFolder As String = ""
        Dim PdfFile As String = ""
      
            PdfFolder = WebMainFolder & "Pdf\"
            If ExportToExcel.Trim = "1" Then
                PdfFile = "\" & Session("UserId") & "-" & Replace(FileName.ToLower, ".rpt", ".xls")            
                If DataOnly = "1" Then
                    Crs.ReportDocument.ExportToDisk(ExportFormatType.ExcelRecord, PdfFolder & PdfFile)
                Else
                    Crs.ReportDocument.ExportToDisk(ExportFormatType.Excel, PdfFolder & PdfFile)
                End If
            Else
                PdfFile = Session("UserId") & "-" & Replace(FileName.ToLower, ".rpt", ".pdf")                
                Crs.ReportDocument.ExportToDisk(ExportFormatType.PortableDocFormat, PdfFolder & PdfFile)
            End If
            Response.Redirect(Request.ApplicationPath & "\Pdf\" & PdfFile, True)
    End Sub

 Sub ConfigureCrsytalReports()
        If Folder <> "" Then
            Crs.Report.FileName = Folder & "\" & FileName
        Else
            Crs.Report.FileName = FileName
        End If

            SetDBLogonForReport()
            If IsDBNull(Session("RecordSelection")) = False Then
                If Session("RecordSelection") <> "" Then
                    Crs.ReportDocument.RecordSelectionFormula = Trim(Session("RecordSelection"))
                Else
                    Crs.ReportDocument.RecordSelectionFormula = ""
                End If
            End If
        Crs.ReportDocument.Refresh() 
 
    End Sub

and put these controls in aspx form

<CR:CrystalReportSource ID="Crs" runat="server">
        </CR:CrystalReportSource>    
        <CR:CrystalReportViewer ID="Crv" runat="server" AutodataBind="true" HasRefreshButton="True" ReportSourceID="Crs" HyperlinkTarget="_new" HasCrystalLogo="False" ToolbarStyle-BackColor="#C0FFFF" ToolbarStyle-BorderColor="White" DisplayGroupTree="False" EnableDrillDown="False" HasDrillUpButton="False" HasToggleGroupTreeButton="False" />
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.