Hello,
I'm trying to export my GridView to csv and I'm getting the following error: Please provide writable stream for export!
bei Telerik.Windows.Controls.GridView.GridViewDataControl.Export(Stream stream, GridViewExportOptions options) in c:\TB\221\WPF_Scrum\Release_WPF\Sources\Development\Controls\GridView\GridView\GridView\Exporting\GridViewDataControl.Exporting.cs:Zeile 17.
bei Data_Transfer_GUI.GridViewExportProvider.<>c__DisplayClass6.<Export>b__0()
bei System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate callback, Object args, Int32 numArgs)
bei MS.Internal.Threading.ExceptionFilterHelper.TryCatchWhen(Object source, Delegate method, Object args, Int32 numArgs, Delegate catchHandler)
This is my code:
The error occurs at this line:
When I hover the stream and open the tooltip I see that
stream.Length' threw an exception of type 'System.ObjectDisposedException'
Second thing is, that I can't understand why the InvalidOperationException is raised. The GridView is on the UI-Thread. It should be not necessary to invoke here. The export is called from a simple command which is called from the UI--Thread.
Do you have an idea why this all happens?
Thank you very much!
Kind regards
I'm trying to export my GridView to csv and I'm getting the following error: Please provide writable stream for export!
bei Telerik.Windows.Controls.GridView.GridViewDataControl.Export(Stream stream, GridViewExportOptions options) in c:\TB\221\WPF_Scrum\Release_WPF\Sources\Development\Controls\GridView\GridView\GridView\Exporting\GridViewDataControl.Exporting.cs:Zeile 17.
bei Data_Transfer_GUI.GridViewExportProvider.<>c__DisplayClass6.<Export>b__0()
bei System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate callback, Object args, Int32 numArgs)
bei MS.Internal.Threading.ExceptionFilterHelper.TryCatchWhen(Object source, Delegate method, Object args, Int32 numArgs, Delegate catchHandler)
This is my code:
var grid = pExportObject
as
RadGridView;
if
(grid !=
null
)
{
string
extension =
"csv"
;
var dialog =
new
SaveFileDialog();
dialog.DefaultExt = extension;
dialog.Filter =
"CSV (*.csv)|*.csv"
;
dialog.FilterIndex = 1;
var format = ExportFormat.Html;
if
(dialog.ShowDialog() ==
true
)
{
FileInfo fi =
new
FileInfo(dialog.FileName);
switch
(fi.Extension)
{
case
".xls"
:
format = ExportFormat.Html;
break
;
case
".xml"
:
format = ExportFormat.ExcelML;
break
;
case
".doc"
:
format = ExportFormat.Html;
break
;
case
".csv"
:
format = ExportFormat.Csv;
break
;
}
using
(var stream = dialog.OpenFile())
{
var exportOptions =
new
GridViewExportOptions();
exportOptions.Format = format;
exportOptions.ShowColumnFooters =
true
;
exportOptions.ShowColumnHeaders =
true
;
exportOptions.ShowGroupFooters =
true
;
try
{
// Check if this thread has access to this object.
grid.Dispatcher.VerifyAccess();
// The thread has access to the object, so update the UI.
grid.Export(stream, exportOptions);
}
// Cannot access objects on the thread.
catch
(InvalidOperationException ex)
{
// Placing job onto the Dispatcher of the UI Thread.
grid.Dispatcher.BeginInvoke(DispatcherPriority.Normal,
new
Action(() => grid.Export(stream, exportOptions)));
}
}
}
The error occurs at this line:
grid.Dispatcher.BeginInvoke(DispatcherPriority.Normal,
new
Action(() => grid.Export(stream, exportOptions)));
When I hover the stream and open the tooltip I see that
stream.Length' threw an exception of type 'System.ObjectDisposedException'
Second thing is, that I can't understand why the InvalidOperationException is raised. The GridView is on the UI-Thread. It should be not necessary to invoke here. The export is called from a simple command which is called from the UI--Thread.
Do you have an idea why this all happens?
Thank you very much!
Kind regards