RadGridView Export is having issue with the generated file.

2 posts, 0 answers
  1. maruti vinod
    maruti vinod avatar
    1 posts
    Member since:
    Sep 2006

    Posted 30 Jan Link to this post

    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;
                         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. 






  2. Vladimir Stoyanov
    Vladimir Stoyanov avatar
    97 posts

    Posted 02 Feb Link to this post


    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. 

    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.
Back to Top