This is a migrated thread and some comments may be shown as answers.

Exception on Export Report Command

2 Answers 87 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Alexander
Top achievements
Rank 1
Alexander asked on 03 Apr 2013, 07:31 AM
Hi

We use ReportViewer for report visualization, print and export in a silverlight application.  

Sometime after we save exported file(no matter what format) the control show exception of type "IO.IO_SharingViolationFile" please see the screen attached.

We need to hide this message from end user and show him some styled popup message with user friendly text.

We tried to add try{ }catch{ } block but sometime it helps sometime now.

then we looked at control ViewModel code and discovered here the reason why we can't catch this exception 

Below is the code listing:

    private void Save()
    {
        string documentName;
        bool flag;
        RenderingResult viewerModel = base.ViewerModel.exportResult;
        if (viewerModel != null)
        {
            SaveFileDialog saveFileDialog = new SaveFileDialog();
            saveFileDialog.DefaultExt = viewerModel.Extension;
            SaveFileDialog saveFileDialog1 = saveFileDialog;
            if (Application.Current.HasElevatedPermissions)
            {
                documentName = viewerModel.DocumentName;
            }
            else
            {
                documentName = null;
            }
            saveFileDialog1.DefaultFileName = documentName;
            saveFileDialog.Filter = ReportViewerModel.SaveExportCommandImpl.BuildSaveFileDialogFilter(base.ViewerModel.selectedExtensionInfo, viewerModel.Extension, base.ViewerModel.TextResources.AllFiles);
            saveFileDialog.FilterIndex = 1;
            SaveFileDialog saveFileDialog2 = saveFileDialog;
            bool? nullable = saveFileDialog2.ShowDialog();
            flag = (!nullable.GetValueOrDefault() ? false : nullable.HasValue);
            if (flag)
            {
                try
                {
                    Stream stream = saveFileDialog2.OpenFile();
                    using (stream)
                    {
                        byte[] documentBytes = viewerModel.DocumentBytes;
                        stream.Write(documentBytes, 0, (int)documentBytes.Length);
                    }
                }
                catch (Exception exception1)
                {
                    Exception exception = exception1;
                    MessageBox.Show(exception.Message);
                }
            }
            return;
        }
        else
        {
            throw new InvalidOperationException(base.ViewerModel.TextResources.UnableToExportError);
        }
    }

Please pay attention on this block 
  try
                {
                    Stream stream = saveFileDialog2.OpenFile();
                    using (stream)
                    {
                        byte[] documentBytes = viewerModel.DocumentBytes;
                        stream.Write(documentBytes, 0, (int)documentBytes.Length);
                    }
                }
                catch (Exception exception1)
                {
                    Exception exception = exception1;
                    MessageBox.Show(exception.Message);
                }

There is standard MessageBox shown and no exception is throw. It make impossible to work with such type of exeptions please fix it


2 Answers, 1 is accepted

Sort by
0
Elian
Telerik team
answered on 05 Apr 2013, 01:44 PM
Hello Alexander,

Thank your for the feedback, we will have your case in mind.
However, in that particular case if an exception is thrown from the command you won't be able to handle it and thus we have decided that the MessageBox is more appropriate than an application crash. 
 

Regards,
Elian
the Telerik team

Have you tried the new visualization options in Telerik Reporting Q1 2013? You can get them from your account.

0
Alexander
Top achievements
Rank 1
answered on 13 Apr 2013, 07:32 PM
Hello,

Thank you, 
It would be helpful if you make this message customizable. Our customers want to see more meaningful and user-friendly message in this case.

Alex
Tags
General Discussions
Asked by
Alexander
Top achievements
Rank 1
Answers by
Elian
Telerik team
Alexander
Top achievements
Rank 1
Share this question
or