Skip to Content

Crystal Reports .NET In Process RAS (Unmanaged) - Report/SubReport manipulation

Dec 02, 2016 at 02:43 PM


avatar image

I'm looking to see if there might be any samples available to look at that show the following:

1. Using In Process RAS

2. Build a report dynamically by adding sections to a report container and then adding sub reports to those sections.

I'm looking to rewrite an old RDC implementation and need to use application data to drive the how the report is built, the sections, and subreports to use.

Please note that I do not see such a sample in the SDK samples offered for .NET In Process RAS.

Thank you,

- Nick

10 |10000 characters needed characters left characters exceeded
* Please Login or Register to Answer, Follow or Comment.

2 Answers

Best Answer
Don Williams
Dec 06, 2016 at 08:58 PM

Hi Nick,

This link should get you started:


Show 1 Share
10 |10000 characters needed characters left characters exceeded

Good Morning,

Again, following up on this after some time. Does anyone know whether it is possible to having existing RDC code and Crystal Reports .NET Ras (Unmanaged ) running in the same project? Specifically, can portions be converted while running old code or might there be conflicts?

Thank you,

- Nick

Nick Coppola Sep 19, 2017 at 09:06 PM

I realize it has been a long time since this was posted, but I am finally trying to attack this issue after a delay. The RDC example that I am working with involves setting the report document, setting parameters, looping through the main report sections to identify report objects and then to apply the connection and parameters to each report object including the main report.

I was hoping there would be some equivalent code available.

It would be great if there was some guide that said if you were doing this in RDC it is this in Inprocess RAS. For example, the first step of the GenerateProjectReport we are creating an instance of CRAXDDRT.Application and CRAXDDRT.Report. I'm not sure what class or classes are the equivalent and which assemblies to import.

Here is what I have:

#Region " Print "Private Sub ClearTempFilesByUser()
        Dim IAs Integer
            Dim strFilePattern AsString= ViewState("username") & "_PM*.pdf"
            Dim FileTable()AsString= IO.Directory.GetFiles("C:\project\temp\", strFilePattern)ForI=0To UBound(FileTable)
                IO.File.Delete(FileTable(I))NextCatch ex AsException
            'Do nothing
        EndTryEnd Sub
    Sub GenerateProjectReport(ByVal strFilter AsString, ByVal strSortField AsString, ByVal strSortDir AsString, ByVal strCommandName AsString)
        Dim crApp AsNew CRAXDDRT.Application
        Dim crReport AsNew CRAXDDRT.ReportIf cbxPrintMarked.Checked Then
            Dim strMarkFilter AsString=""
            Dim XAs Integer
            Dim objChechBox AsCheckBoxForX=0To dgrProjects.Items.Count-1
                objChechBox = dgrProjects.Items.Item(X).Cells(12).FindControl("cbxMarked")IfNot IsNothing(objChechBox)ThenIf objChechBox.Checked Then strMarkFilter += dgrProjects.Items(X).Cells(1).Text&","
                    objChechBox = Nothing
                EndIfNextIfNot Trim(strMarkFilter)="" _Then strFilter ="WHERE PID IN(" & Mid(strMarkFilter, 1, Len(strMarkFilter) - 1) & ")" _Else lblError.Text="No record was marked for printing." : Exit SubEndIfTry
            ' Open the report
            '-----------------------------------------------SelectCase UCase(strCommandName)Case"SUMMARY" : crReport = crApp.OpenReport("Summary.rpt", 0)Case"SUMMARY2" : crReport = crApp.OpenReport("Summary2.rpt", 0)CaseElse: crReport = crApp.OpenReport("Detail.rpt", 0)EndSelect
            ' Set the ConnectionInfo properties for logging onto the Database 
            ' Set parms based upon needs andincludingall subreports
            Dim oParms As CRAXDDRT.ParameterFieldDefinitions
            Dim oParm As CRAXDDRT.ParameterFieldDefinition
            ' set parms for the mainreport;in this case it has two
            oParms = crReport.ParameterFields
            oParm = oParms.Item(1)
            oParm = oParms.Item(2)
            oParm = oParms.Item(3)
            oParm = oParms.Item(4)
            oParm.ClearCurrentValueAndRange()If UCase(strCommandName)="SUMMARY" _Then oParm.SetCurrentValue(True) _
                    Else oParm.SetCurrentValue(False)Catch exMain AsExceptionIfNot IsNothing(crApp)Then
                crReport = Nothing
                crApp = Nothing
        ' Handle Viewing
        Dim sSaveFileName AsString=""Try
            'Build standard filename and path
            Dim strDateTimeStamp AsString=Format(Date.Now,"MMddyyyy_hhmmss")
            sSaveFileName ="C:\project\temp\" & _
                            ViewState("username") & "_PM" & _
                            ViewState("PIDselected") & "_" & _
                            strDateTimeStamp &"_report.pdf"
            'Call the export
            ExportFile(crReport, sSaveFileName)
            'Manage closing of com objects
            crReport = Nothing
        Catch exMain2 AsExceptionIfNot IsNothing(crApp)Then
                crReport = Nothing
                crApp = Nothing
        'Extracting partial path from physical path and forming a virtual path to the file
        'Register javascript to the virtual path
        Dim strTable()AsString
        Dim IAsByte, strTemp AsString=""
        ' Reverse left slashes toright
        strTable =Split(sSaveFileName,"\")ForI=4To UBound(strTable): strTemp = strTemp &"/" & strTable(I) : Next
        Dim strURL AsString
        Dim strOptions AsString
        strURL ="http://" & Request.ServerVariables("SERVER_NAME") & "/temp/" & strTemp
        strOptions ="LEFT=10, TOP=10, HEIGHT=650, WIDTH=600, STATUS=no, SCROLLBARS=yes RESIZABLE=yes"Page.ClientScript.RegisterClientScriptBlock(GetType(Main),"ShowReport", "<script language='JavaScript'>" & vbCrLf & _"'" & strURL & "', '', '" & strOptions & "', 'False')</script>")End Sub
    Sub SetReportTableProps(ByRef objReport As CRAXDDRT.Report)
        Dim CrTables As CRAXDDRT.DatabaseTables
        'Indiv Table(reused)
        Dim CrTable As CRAXDDRT.DatabaseTable
        'This code works for both usertablesand stored 
        'procedures.Set the CrTables to the Tablescollection 
        'of the report 
        ' Acquire referencetotablecollection
        CrTables = objReport.Database.Tables
        'Loop through each tablein the reportand apply the 
        'LogonInfo information 
        Dim objProperties As CRAXDDRT.ConnectionProperties
        For Each CrTable In CrTables
            objProperties = CrTable.ConnectionProperties
            'If your DatabaseName ischangingat runtime, specify 
            'the table location. 
            'For example,when you are reporting offof a 
            'Northwind databaseonSQL server you 
            'should have the following lineofcode: 
            CrTable.Location = AppSettings("Initial Catalog") & ".dbo." & CrTable.Location.Substring(CrTable.Location.LastIndexOf(".") + 1)NextEnd Sub
    Private Sub SetDBConnProps(ByRef objParms As CRAXDDRT.ConnectionProperties)
        objParms.Item("Provider").value = AppSettings("Provider")
        objParms.Item("Data Source").value = AppSettings("Data Source")
        objParms.Item("Initial Catalog").value = AppSettings("Initial Catalog")
        objParms.Item("User ID").value = AppSettings("User ID")
        objParms.Item("Password").value = AppSettings("Password")End Sub
    Sub PrepareSubReports(ByRef objReport As CRAXDDRT.Report)
        Dim CrSections As CRAXDDRT.Sections
        Dim CrSection As CRAXDDRT.Section
        Dim CrReportObjects As CRAXDDRT.ReportObjects
        Dim CrSubReport As CRAXDDRT.SubreportObject
        Dim crCollSubReport AsNewCollection
        'Loop through each sectionto identify subreports
        CrSections = objReport.Sections
        'CrSections = rptBindLetter.ReportDefinition.Sections
        Dim iAs Integer
        For Each CrSection In CrSections
            CrReportObjects = CrSection.ReportObjects
            Fori=1To CrReportObjects.CountIf CrReportObjects.Item(i).Kind= CrystalDecisions.Shared.ReportObjectKind.SubreportObject Then
                    CrSubReport = CrReportObjects.Item(i)
                    'CrSubReport = CType(CrReportObject, CRAXDDRT.SubreportObject)
                    'oSubRpt = CrSubReport.OpenSubreport(CrSubReport.SubreportName)
                    PrepareSubReports(crCollSubReport.Item(crCollSubReport.Count))EndIfNextNextEnd Sub
    Sub ExportFile(ByVal oRpt AsReport, ByVal sSaveFileName AsString)With oRpt
            .ExportOptions.DiskFileName = sSaveFileName
            .ExportOptions.DestinationType = CRAXDDRT.CRExportDestinationType.crEDTDiskFile
            SelectCase UCase(Right(sSaveFileName,3))Case"PDF".ExportOptions.FormatType = CRAXDDRT.CRExportFormatType.crEFTPortableDocFormat
                Case"DOC".ExportOptions.FormatType = CRAXDDRT.CRExportFormatType.crEFTWordForWindows
                Case"RTF".ExportOptions.FormatType = CRAXDDRT.CRExportFormatType.crEFTRichText
                Case"XLS".ExportOptions.FormatType = CRAXDDRT.CRExportFormatType.crEFTExcel97
            EndSelect.Export(False)EndWithEnd Sub
#End Region
10 |10000 characters needed characters left characters exceeded