删除临时文件夹中 Crystal Report 生成的文件 - Visual Studio 2008
您好,我在下面粘贴了一段代码,用于显示报告。我正在使用 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
有时,即使您对
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 byGC.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 !!!!适用于 Crystal 报告版本 13 及更高版本。清除临时文件。在 CrystalReportViewer 的 Unload 事件中调用 dispose
protected void crReportViewer_Unload(object sender, EventArgs e)
{
关闭报告();
}
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();
}