RadGridView Export is having issue with the generated file.

5 posts, 0 answers
  1. maruti vinod
    maruti vinod avatar
    5 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;
                        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. 

     

     

     

     

     

  2. Vladimir Stoyanov
    Admin
    Vladimir Stoyanov avatar
    178 posts

    Posted 02 Feb Link to this post

    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.
  3. maruti vinod
    maruti vinod avatar
    5 posts
    Member since:
    Sep 2006

    Posted 07 Mar in reply to Vladimir Stoyanov Link to this post

    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,

  4. Vladimir Stoyanov
    Admin
    Vladimir Stoyanov avatar
    178 posts

    Posted 12 Mar Link to this post

    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.
  5. maruti vinod
    maruti vinod avatar
    5 posts
    Member since:
    Sep 2006

    Posted 15 May in reply to Vladimir Stoyanov Link to this post

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

     

    Thanks,

    Vinod.

Back to Top