How to run cleanup code after calling Crystal Reports ExportToHttpResponse method?

We had a problem in our ASP.Net application, where the Crystal Reports engine leaves garbage .tmp files in the Temp folder of the server after creating reports for users.

So, we are trying to figure out how to run the .Close () and .Dispose () methods of the Report object, but we find that the code does not start after export.

MyReport.Report.ExportToHttpResponse(ExportFormatType.PortableDocFormat, this.Response, true, "My_Report"); MyReport.Report.Close(); MyReport.Report.Dispose(); 

The breakpoints set on the last two lines never hit, and we also tried to put different code to check the processing. None of this is happening. (I also saw this question on other sites with similar code, but did not answer)

I assume that the ExportToHttpResponse method returns the file stream (PDF) to the user at this point, ending the processing, so the rest of the code does not run. If this is the case, how can we get CR to clean up the temporary files that should be done by the Close () and Dispose () methods? Do we need to perform manual cleaning after the fact?

+4
source share
2 answers

I have no way to reproduce this problem, so I will throw it there so you can use the using statement, which allows you to specify when the objects should be released.

What is a C # Using block and why should I use it? http://msdn.microsoft.com/en-us/library/yh598w02(VS.80).aspx

Not tried, but I think you could do something like

 using(MyReport m = new MyReport()) { m.Report.ExportToHttpResponse(ExportFormatType.PortableDocFormat, this.Response, true, "My_Report"); } 

As I type it, I’m not sure that it will be very different from what you already have, but oh, well, try something. It works in my head. :)

Hope this helps.

+3
source

I really had this exact problem, and I found that you can get the Close () and Dispose () methods to run by including the export method in the Try Catch block and placing the Close () and Dispose () methods at the end for example:

  Try MyReport.Report.ExportToHttpResponse(ExportFormatType.PortableDocFormat, Page.Response, True, ReportName) Catch ex As System.Exception Finally MyReport.Report.Close() MyReport.Report.Dispose() End Try 
+3
source

Source: https://habr.com/ru/post/1301041/


All Articles