FireFox adds ".XLS" to File Name

Hi,

I found that FireFox adds a ".XLS" to your file name if you create an excel file and give it to the user via MemoryStream.  In the FireFox download prompt if you choose "Save As" it works as expected.  However, if you choose "Open" it adds ".XLS" to your file name.

I found a way to get it to work and thought I'd share in case someone else ran into this.  According to this website: https://gullele.com/firefox-adds-xls-extension-when-downloading-excel-files-from-problem/ you need to set MIME type differently.  I tried it and it worked for Firefox, Chrome and IE.

Sample code below:

            ExcelEngine excelEngine = new ExcelEngine();

            IApplication application = excelEngine.Excel;

            // create new workbook
            IWorkbook workbook = application.Workbooks.Create();
            IWorksheet sheet = workbook.Worksheets[0];
         
            sheet.Range["A1"].ColumnWidth = 25.86;

            //string contentType = "Application/msexcel"; - when contentType is "Application/msexcel" firefox adds ".XLS" to the file name when opening
            string contentType = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"; // this works correctly in each browser that I tried.
            workbook.Version = ExcelVersion.Excel2016;
            string fileName = "ScoreCard.xlsx";

            try
            {
                MemoryStream ms = new MemoryStream();
                workbook.SaveAs(ms);
                ms.Position = 0;

                workbook.Close();
                excelEngine.Dispose();

                return File(ms, contentType, fileName);
            } catch
            {
                return View();
            }

Thanks,
Chris

1 Reply

AV Abirami Varadharajan Syncfusion Team May 15, 2018 10:58 AM UTC

Hi Chris, 
 
Thank you for contacting Syncfusion support. 
 
We are able to reproduce the issue “File gets corrupted while downloading Excel file from some of the browsers” and the issue has been fixed in our release version 15.4 SP – 1. So, we request you to upgrade to our latest release version to get this issue resolved which is available for download under following location. 
 
Download Link:    
 
Please upgrade and let us know if this issue gets resolved at your end. 
 
Regards, 
Abirami. 


Loader.
Up arrow icon