删除临时文件夹中 Crystal Report 生成的文件 - Visual Studio 2008

发布于 2024-11-24 07:47:05 字数 997 浏览 3 评论 0原文

您好,我在下面粘贴了一段代码,用于显示报告。我正在使用 Visual Studio 2008 Crystal Report 引擎。它与这段代码配合得很好

问题: 每次运行报告时,它通常会在临时文件夹 c 中生成一个 ('.*tmp', '.*rpt') 文件:\windows\temp 但是,我们可以通过在应用程序池上设置回收来摆脱 *.tmp 文件,但需要一种方法来摆脱 .rpt 文件。

找到解决方案:在报表对象上调用Close()Dispose()。我正在做的方式是 crReportDoc.Close() 然后 crReportDoc.Dispose()

实际问题: 如果调用 Dispose() ,报告会出现以下错误 “对象引用未设置为对象的实例”

如果其中一位伙伴可以帮助我找到解决方案,我将非常感激,因为我对编程还很陌生。

谢谢

        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

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

本王不退位尔等都是臣 2024-12-01 07:47:05

有时,即使您对 ReportDocument 对象调用 dispose,然后调用 GC.Collect().rpt 文件仍然位于 Temp< 中/strong> 文件夹未清理。并且有一个限制,就是不可以。 Temp 文件夹中的 .rpt 文件,之后 CR 停止执行进一步的报告请求。

奇怪的是,当您在函数或事件处理程序中声明 ReportDocument 对象时,就会发生这种情况。

但是,如果您在页面范围全局上下文中声明您的 ReportDocument,那么当您在 Page_Unload() 事件中调用 Dispose 方法时,水晶报表会愉快地清除临时 .rpt 文件! !!

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 !!!!

若水微香 2024-12-01 07:47:05

适用于 Crystal 报告版本 13 及更高版本。清除临时文件。在 CrystalReportViewer 的 Unload 事件中调用 dispose

protected void crReportViewer_Unload(object sender, EventArgs e)
{
关闭报告();
}

    /// <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
        {

        }

    }

For CRystal Report Versions 13 and above. To clear temporary files. Call the dispose in the CrystalReportViewer's Unload event

protected void crReportViewer_Unload(object sender, 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
        {

        }

    }
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文