Get rid of Crystal Report generated files in temp folder - Visual Studio 2008

Ash picture Ash · Jul 14, 2011 · Viewed 10k times · Source

Hi I have pasted below a piece of code where I am displaying a report. I am using Visual Studio 2008 Crystal Report engine. It works all good with the piece of code

Problem: Everytime a report is being run it generates a ('.*tmp', '.*rpt') files typically in a temp folder c:\windows\temp however we can get rid of the *.tmp files by setting a recycle on the application pool but need a way to get rid of the .rpt files.

Found solution: Call Close() and Dispose() on the report object. The way I am doing is crReportDoc.Close() then crReportDoc.Dispose()

Actual Problem: If Dispose() is called the report comes up with the following error 'Object reference not set to an instance of an object'

I will really appreciate if one of the fellow mates can help me with a solution as I am quite new to programming.

Thanks

        Dim crReportDoc = New CrystalDecisions.CrystalReports.Engine.ReportDocument           
        crReportDoc = Session("ReportDocument")
        ReportViewer.DisplayToolbar = True
        ReportViewer.EnableDrillDown = True
        ReportViewer.DisplayGroupTree = False
        ReportViewer.Visible = True
        ReportViewer.DisplayToolbar = True
        ReportViewer.ReportSource = crReportDoc

Answer

Deb picture Deb · Apr 23, 2012

Some times even though you call dispose on your ReportDocument object followed by GC.Collect() still the .rpt files in Temp folder are not cleaned up. And there is a limit to no. of .rpt files in a Temp folder after which CR stops executing further report requests.

Strangely this happens when you declare your ReportDocument object in side a function or event handler.

But if you declare your ReportDocument in a Page wide global Context then crystal reports happily cleans of temp .rpt files when you call the Dispose method in the Page_Unload() event !!!!