cancel
Showing results for 
Search instead for 
Did you mean: 

WPF Crystal report throws an exception when user tries to replace a file which is open during export of report.

Former Member
0 Kudos

I am using the latest version of crystal report CRforVS_13_0_10 with Visual Studio 2013.

I am working a WPF application and using the WPF crystalreportviewer control.

The steps to reproduce the exception is ,

1) Create a report.

2) Export report with sample.xls  as file name

3) Now open the sample.xls file in Excel

4) Again export the report with sample.xls  as file name

5) There is dialog which asks "Do you want to replace existing file sample.xls"

6)Click "Yes"

7) Now the exception will be thrown.

This is System.IO.IOException which is thrown by crystal report  when user tries to save the file which is already opened by user. Also there is no event provided to handle Export_click for WPF CrystalReportViewer where I can handle this.

Accepted Solutions (1)

Accepted Solutions (1)

former_member183750
Active Contributor
0 Kudos

Are you using .Close and .Dispose on the report object after the firs export?

If you delete the xls exported in step (2) and then export, do you still get the issue?

- Ludek

Senior Support Engineer AGS Product Support, Global Support Center Canada

Follow us on Twitter

Former Member
0 Kudos

No, I am not using .Close and .Dispose on the report object after the first export.

I export the to abc.xls  then I open abc.xls on my desktop.

Now as the file is open  and I again export with  same file name crystal report throws internal exception.

Its very easy to reproduce this on any crystal report WPF application.

0 Kudos

I can replicate the issue. Not sure how we can hook into the System.IO process to capture the exception. I have not played with that part yet...

I created my own export button and wrapped it in a try/catch and this is what I get:

Which is what you would expect rather than a Null Exception error:

We'll have to do more testing to see how or if System IO errors can caught outside of CR.

Don

0 Kudos

Issue has been escalated to R&D.

Case number is:

Incident 832657 / 2014 / WPF Viewer - Exporting to a locked file

Kbase article is:

2062628 - WPF Viewer - Exporting to a locked file throws exception


Don

Former Member
0 Kudos

Hi team,

In which version I can expect the fix for this and how long it will take?

Thanks for adding to your case number.

0 Kudos

Hi Manini,

SP 11 is due out end of this month so its too late to get it in this patch.

Typically patches for this product are released every quarter so next should be end of December or early January.

FYI - WPF viewer is first version in this product so it's still "new" so it has not been enhanced as much as the CR.Windows.Forms viewer. So you may want to look into using it rather than the WPF viewer.

This product only releases full Service Packs, there are no plans to release between them.

Another option is to use Windows API's to test if the file is locked before exporting and then pop up a message to indicate it is and to close before continuing...

Don

0 Kudos

Hi Manini,

Junjie in R&D had a look at this issue and here's how to work around it:

reportViewer.ViewerCore.Error += new
SAPBusinessObjects.WPF.Viewer.ExceptionEventHandler(ViewerCore_Error);

void ViewerCore_Error(object source,
SAPBusinessObjects.WPF.Viewer.ExceptionEventArgs e)

         {

             if (e.Exception != null)

             {

                 MessageBox.Show(e.Exception.Message);

                 e.Handled = true;

             }

         }

Please test and update if you have issues or questions.

Thanks again

Don

Answers (0)