Search code examples
c#crystal-reports

Clear crystal reports temp files


Crystal reports temp files, delete the code for the close button in c# form. How do I clear the report cache? Thanks in Advance.


Solution

  • This link really helped me.Try it

    http://www.pedautreppe.com/post/Crystal-Reports-generates-temporary-files.aspx

        private void Page_Unload(object sender, EventArgs e) 
        { 
            CloseReports(cr); 
            cr.Dispose(); 
            CrystalReportViewer1.Dispose(); 
            CrystalReportViewer1 = null; 
    
        } 
    
    
        private void CloseReports(ReportDocument reportDocument) 
        { 
            Sections sections = reportDocument.ReportDefinition.Sections; 
            foreach (Section section in sections) 
            { 
                ReportObjects reportObjects = section.ReportObjects; 
                foreach (ReportObject reportObject in reportObjects) 
                { 
                    if (reportObject.Kind == ReportObjectKind.SubreportObject) 
                    { 
                        SubreportObject subreportObject = (SubreportObject)reportObject; 
                        ReportDocument subReportDocument = subreportObject.OpenSubreport(subreportObject.SubreportName); 
                        subReportDocument.Close(); 
                    } 
                } 
            } 
            reportDocument.Close(); 
        } 
    

    Globally open the report and globally close it inside the page.It will help