Data export fails: Please provide writable stream for export!

4 posts, 1 answers
  1. Nicole
    Nicole avatar
    25 posts
    Member since:
    Nov 2010

    Posted 21 May 2013 Link to this post

    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







  2. Dimitrina
    Admin
    Dimitrina avatar
    3769 posts

    Posted 21 May 2013 Link to this post

    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.

  3. Nicole
    Nicole avatar
    25 posts
    Member since:
    Nov 2010

    Posted 21 May 2013 Link to this post

    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?
  4. Answer
    Dimitrina
    Admin
    Dimitrina avatar
    3769 posts

    Posted 22 May 2013 Link to this post

    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.

Back to Top