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

RadGridView ExportAsync generates an empty file

3 Answers 95 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Michel Cossette
Top achievements
Rank 1
Michel Cossette asked on 23 Mar 2018, 03:10 PM

Hi, 

I tried using the export functionality of the RadGridView and I found that the ExportAsync generates an empty file. When I use the plain Export method instead, it works correctly. Can someone take a look at this and confirm whether it works or not.

 

Thanks.

3 Answers, 1 is accepted

Sort by
0
Martin Ivanov
Telerik team
answered on 26 Mar 2018, 01:39 PM
Hello Michael,

I am not sure what could cause this. May I ask you to post some runnable code snippets demonstrating your set up, what format you export and what the issue is? Alternatively, you can open a new support ticket from your telerik.com account and attach an isolated project there. 

Thank you for any help you can provide.

Regards,
Martin Ivanov
Progress Telerik
Want to extend the target reach of your WPF applications, leveraging iOS, Android, and UWP? Try UI for Xamarin, a suite of polished and feature-rich components for the Xamarin framework, which allow you to write beautiful native mobile apps using a single shared C# codebase.
0
Michel Cossette
Top achievements
Rank 1
answered on 10 Apr 2018, 09:09 PM

Thanks for your reply, Here are some more details that might help figuring out what going on, first we have a RadDataPager along with the RadGridView. The working code right now (not using async), what I tried was only replacing the lines 6 to 12 with this code below, which creates an empty file. Thanks again..

1.GridView2.ExportAsync(stream,new GridViewExportOptions()
3.      {
4.          Format = ExportFormat.ExcelML,
5.          ShowColumnHeaders = true,
6.          ShowColumnFooters = true,
7.          ShowGroupFooters = false,
8.      }, false);

 

 

01.

// This is our working code

02.PageSize = 0;
03. 
04.using (var stream = sfd.OpenFile())
05.{
06.   grid.ExportToXlsx(stream,
07.   new GridViewDocumentExportOptions
08.    {
09.      ShowColumnHeaders = true,
10.      AutoFitColumnsWidth = true,
11.      ExportDefaultStyles = true,
12.    });
13. }
14.PageSize = 30;
0
Martin Ivanov
Telerik team
answered on 12 Apr 2018, 10:12 AM
Hi Michael,

Thank you for the code. I tested this and I still cannot tell what the issue is on your side, but on my side the ExportAsync method works. However, I hit couple of issues while I was setting up the test project because I missed the async operations specifics. For example, if you wrap the code snippet with the async method in a 'using' with the stream as in your second code snippet, a silent exception will be thrown. You check for this in the Output pane of Visual Studio - the exception prints there. And it states that the stream is already disposed and you cannot modify it. This happens because when the compiler goes out of the using the stream disposes. However, the async operation that exports the gridview data to the stream still works and the exception occurs. Therefore, the file is empty.

The other issue I hit was that I set the last parameter of the ExportAsync method to false, but I never closed the stream. So, the file is not empty but it cannot be accessed - an error in Excel appears. In this case I had to close the application in order to open the file.

So, in summary, to use the ExportAsync method I would recommend you to avoid using the 'using' keyword and set the last parameter of the method to true, if you don't have a specific reason not to do so. You can check this approach in the attached project. I hope it helps.

Regards,
Martin Ivanov
Progress Telerik
Want to extend the target reach of your WPF applications, leveraging iOS, Android, and UWP? Try UI for Xamarin, a suite of polished and feature-rich components for the Xamarin framework, which allow you to write beautiful native mobile apps using a single shared C# codebase.
Tags
GridView
Asked by
Michel Cossette
Top achievements
Rank 1
Answers by
Martin Ivanov
Telerik team
Michel Cossette
Top achievements
Rank 1
Share this question
or