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

Data export fails: Please provide writable stream for export!

3 Answers 72 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Nicole
Top achievements
Rank 1
Nicole asked on 21 May 2013, 02:46 PM
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:

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







3 Answers, 1 is accepted

Sort by
0
Dimitrina
Telerik team
answered on 21 May 2013, 02:53 PM
Hello,

I am not able to reproduce any issue on the WPF Demos. Would you please check what do you do differently for your solution? 

Kind regards,
Didie
the Telerik team

Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

0
Nicole
Top achievements
Rank 1
answered on 21 May 2013, 03:00 PM
Hello Didie,

thank you for your answer.

I have an update:
When I hover the stream and open the tooltip I see that
stream.Length' threw an exception of type 'System.ObjectDisposedException'

How could  that be? Is the export method asynchron?
0
Accepted
Dimitrina
Telerik team
answered on 22 May 2013, 11:26 AM
Hi,

What if you remove this line:

grid.Dispatcher.VerifyAccess();
Then you can also set the stream position back to start:
stream.Position = 0

I am not able to reproduce such an issue locally when following the approach from the Exporting demo.

Regards,
Didie
Telerik

Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

Tags
GridView
Asked by
Nicole
Top achievements
Rank 1
Answers by
Dimitrina
Telerik team
Nicole
Top achievements
Rank 1
Share this question
or