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
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