Get rid of files created by Crystal Reports in temp folder - Visual Studio 2008

Hi, I have inserted the code snippet below where I am showing the report. I am using Visual Studio 2008 Crystal Report engine. It works great with a piece of code

Problem: Each time the report is run, it generates files (.. tmp, .. rpt) in the temp folder c: \ windows \ temp however we can get rid of the * .tmp files by setting up processing in the application pool, but you need to get rid from .rpt files.

Solution Found: Call Close () and Dispose () in the report object. The way I do this is crReportDoc.Close (), then crReportDoc.Dispose ()

Actual problem: If Dispose () is called , the following error appears in the report : "The object reference is not installed in the object instance"

I will be very grateful if one of my teammates can help me with the solution, since I am completely new to programming.

thank

        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
+5
source share
2 answers

, dispose ReportDocument , GC.Collect(), .rpt Temp . . .rpt Temp, CR .

, ReportDocument .

ReportDocument , .rpt, Dispose Page_Unload()!!!!

+2

CRustal Report 13 . . dispose Unload CrystalReportViewer

protected void crReportViewer_Unload ( , EventArgs e)       {           CloseReport();       }

    /// <summary>
    /// This method is used to clear the temporary files created by Crystal Reports
    /// </summary>
    protected void CloseReport()
    {
        try
        {
            if(cryRpt != null)
            {
                Sections objSections = cryRpt.ReportDefinition.Sections;
                foreach (Section objSection in objSections)
                {
                    ReportObjects objReports = objSection.ReportObjects;
                    foreach(ReportObject rptObj in objReports)
                    {
                        if(rptObj.Kind.Equals(CrystalDecisions.Shared.ReportObjectKind.SubreportObject))
                        {
                            SubreportObject subreportObject = (SubreportObject)rptObj;
                            ReportDocument subReportDocument = subreportObject.OpenSubreport(subreportObject.SubreportName);
                            subReportDocument.Close();
                        }
                    }
                }
                cryRpt.Close();
                cryRpt.Dispose();
            }
            if(crReportViewer != null)
            {
                crReportViewer.ReportSource = null;
                crReportViewer.Dispose();
            }
        }
        catch
        {

        }

    }
+1

All Articles