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

RadGridView Export is having issue with the generated file.

4 Answers 234 Views
GridView
This is a migrated thread and some comments may be shown as answers.
maruti vinod
Top achievements
Rank 1
maruti vinod asked on 30 Jan 2018, 01:28 PM

I have the blow routine

private void btn_ExportExcel(object sender, RoutedEventArgs e)
        {
            if (dgResults.DataContext == null) return;

            var extension = "xls";
            var dialog = new Microsoft.Win32.SaveFileDialog()
            {
                DefaultExt = extension,
                Filter = String.Format("{1} files (*.{0})|*.{0}|All files (*.*)|*.*", extension, "Excel"),
                FilterIndex = 1
            };
            if (dialog.ShowDialog() == true)
            {
               dgResults.ElementExporting -= ElementExporting;
                dgResults.ElementExporting += ElementExporting;

                 using (var stream = dialog.OpenFile())
                {

                    // dgResults.ExportSettings.ExportOnlyData = true;
                    // dgResults.ExportSettings.UseItemStyles = true;
                    dgResults.Export(stream,
                     new GridViewExportOptions()
                     {

                         Format = ExportFormat.Html,
                         ShowColumnHeaders = true,
                         ShowColumnFooters = false,
                         ShowGroupFooters = false,

                     });
                }
                                MessageBox.Show("Exporting to Excel has completed successfully");
            }
        }

The routine is executing succesfully, after saving the resultant Excel, when I try to open it, its showing an error messsage as below...

"The file format and extension of 'File1.xls' don't match. The file could be currupted or unsafe. Unless you trust its source, don't open it. Do you want to open it anyway?"

I tried with different formats like csv, html, ExcelML, the same error pops out. When I click 'Yes', its opening with the perfect data.

I would like to request, any help to fix this issue.

Thanks in advance. 

 

 

 

 

 

4 Answers, 1 is accepted

Sort by
0
Vladimir Stoyanov
Telerik team
answered on 02 Feb 2018, 11:53 AM
Hello,

Thank you for the provided code snippet.

The alert is a new security feature called Extension Hardening, which ensures that the file content being opened matches the extension type specified in the shell command that is attempting to open the file. You can take a look at the following topic where this issue has been discussed. In order to avoid receiving that warning what I can suggest is using the ExportToXlsx method to export the RadGridView. 

Regards,
Vladimir Stoyanov
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
maruti vinod
Top achievements
Rank 1
answered on 07 Mar 2018, 10:40 PM

Thanks for the response,

I have used the same routine, still the error exists. And one more query is, the ExportExcel option is not there in recent version. Its removed. Can you please suggest me alternate solution for this,

0
Vladimir Stoyanov
Telerik team
answered on 12 Mar 2018, 02:40 PM
Hello,

May I ask you to check if you are using the ExportToXlsx method, since in the provided code snippet it seems that the Export method is used? The ExportToXlsx method was introduced in Q1 2015 and I believe it should suit your requirements. I have prepared a sample project demonstrating it and attached it for your reference.

Please give the approach in the attached project a try and let me know if I can be of any further assistance.

Regards,
Vladimir Stoyanov
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
maruti vinod
Top achievements
Rank 1
answered on 15 May 2018, 01:33 PM

Sorry for delayed Reply. Thanks for the code sample. That works for us. Really appreciate the help.

 

Thanks,

Vinod.

Tags
GridView
Asked by
maruti vinod
Top achievements
Rank 1
Answers by
Vladimir Stoyanov
Telerik team
maruti vinod
Top achievements
Rank 1
Share this question
or