This question is locked. New answers and comments are not allowed.
I wrote a CSV export event handler for a RadGridView based on this example:
http://demos.telerik.com/silverlight/#GridView/ExportingPagedData
If the saved file is open by Excel already, then the dialog.OpenFile() call throws an IOException. I display this to the user with a RadWindow.Alert() from the catch(IOException...) block, however, I subsequently get the following exception:
Error: An unknown error has occurred.
Detail: System.InvalidOperationException
This operation can only occur on the UI Thread.
at System.Windows.Hosting.NativeHost.VerifyThread()
at System.Windows.SaveFileStream.Dispose(Boolean disposing)
at System.IO.FileStream.Finalize()
I can't check stream.CanWrite because it does not get past the OpenFile() call.
I put the RadWindow.Alert() on the Dispatcher as a test without any apparent effect.
How can I handle this properly without generating this subsequent error?
Thanks,
Tim
http://demos.telerik.com/silverlight/#GridView/ExportingPagedData
private
void
ExportCSV(
object
sender, RoutedEventArgs e)
{
SaveFileDialog dialog =
new
SaveFileDialog
{DefaultExt =
".csv"
, Filter =
"CSV Files|*.csv|All Files|*.*"
, FilterIndex = 1};
bool
? result = dialog.ShowDialog();
if
(result ==
true
)
{
int
originalPageSize = EventDataPager.PageSize;
int
originalPageIndex = EventDataPager.PageIndex;
EventDataPager.PageSize = 0;
try
{
using
(Stream stream = dialog.OpenFile())
{
EventViewerGridView.Export(stream, GridViewExportOptions);
}
}
catch
(IOException ioe)
{
RadWindow.Alert(ioe.Message);
}
EventDataPager.PageSize = originalPageSize;
EventDataPager.PageIndex = originalPageIndex;
}
}
If the saved file is open by Excel already, then the dialog.OpenFile() call throws an IOException. I display this to the user with a RadWindow.Alert() from the catch(IOException...) block, however, I subsequently get the following exception:
Error: An unknown error has occurred.
Detail: System.InvalidOperationException
This operation can only occur on the UI Thread.
at System.Windows.Hosting.NativeHost.VerifyThread()
at System.Windows.SaveFileStream.Dispose(Boolean disposing)
at System.IO.FileStream.Finalize()
I can't check stream.CanWrite because it does not get past the OpenFile() call.
I put the RadWindow.Alert() on the Dispatcher as a test without any apparent effect.
How can I handle this properly without generating this subsequent error?
Thanks,
Tim