views:

251

answers:

1

We're having a problem in our ASP.Net application where the Crystal Reports engine leaves garbage .tmp files in the server's Temp folder after generating reports for the users.

So we're trying to figure out how to run the .Close() and .Dispose() methods on the Report object, but we're finding that the code never gets run after the export occurs.

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

MyReport.Report.Close();
MyReport.Report.Dispose();

Breakpoints set on the last two lines never get hit, and we've also tried putting other code there to test the processing. None of it runs. (I've also seen this question on other sites with similar code, but no answers)

I assume the ExportToHttpResponse method is returning a file stream (PDF) to the user at that point, ending the processing so the rest of the code doesn't get run. If that's the case, how do we get CR to perform a cleanup on the temp files, which the Close() and Dispose() methods are supposed to do? Do we have to implement a manual after-the-fact cleanup?

+2  A: 

I don't have a way of reproducing this issue so I'll throw out there that you may be able to use the using statement which allows you to specify when objects should be released.

http://stackoverflow.com/questions/212198/what-is-the-c-using-block-and-why-should-i-use-it http://msdn.microsoft.com/en-us/library/yh598w02(VS.80).aspx

Haven't tried this, but I think you might be able to do something like

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

As I'm typing it I'm not sure that it would be much different than what you have already, but oh well, it's something to try. In my head this works. :)

Hope it helps.

Dusty
Thanks. We had thought of this as a possibility, and it seems like it would work. The other approach we're trying is to use Page_Unload.
Raelshark