1

I am trying to export some content as .csv file as shown in the below code.

function ExportToCSV(gridContent, file_name) {
    if (detectIE()) { // Checks IE and Edge
            var IEwindow = window.open();
            IEwindow.document.write(gridContent);
            IEwindow.document.close();
            IEwindow.document.execCommand('SaveAs', true, file_name + ".csv");
     } else {
          ..... for other browsers.........
     }
  }

I am having issue document.execCommand which is not functioning like it functions in internet explorer, i,e prompting the dialog window to store .csv file internet explorer.

document.execCommand is failing in Edge, What i am missing ?

Shankar
  • 2,565
  • 8
  • 29
  • 56
  • Do you mean it is not showing the Save file dialog and directly download the file? Go to the Settings and check whether 'Ask me what to do with each download' option is disabled. Let us know which exact version of the MS Edge browser you are using for this test? – Deepak-MSFT Apr 07 '20 at 10:15
  • 1) `Ask me what to do with each download` option is disable ==> Yes it is disabled. 2) version of the MS Edge browser you are using for this test? ==> 44.18362.449.0 – Shankar Apr 07 '20 at 10:24
  • Enable that option. then the Edge will show the file download dialog. Do you get any error or file not get downloaded? Please try to provide detailed information about your issue. – Deepak-MSFT Apr 07 '20 at 10:34
  • @Shankar, Is there any progress on this issue? If you had found the solution then please try to post it as an answer and try to mark your own answer as an acceptable answer for this question after 48 hrs, when it is available to mark. If the issue still persists then try to refer the suggestions on the thread and let us know about your status for this issue. We will try to provide further suggestions. Thanks for your understanding. – Deepak-MSFT Apr 13 '20 at 09:41
  • I found solution from this answer == > **https://stackoverflow.com/questions/17836273/export-javascript-data-to-csv-file-without-server-interaction/27699027#27699027** – Shankar Apr 14 '20 at 06:11

1 Answers1

0
function ExportToCSV(gridContent, file_name) {
if (detectIE()) { // Checks IE and Edge
     var _fileName = file_name + ".csv";
     var blob = new Blob([decodeURIComponent(encodeURI(gridContent))], {
         type: "text/csv;charset=utf-8;"
     });
     navigator.msSaveBlob(blob, _fileName);
 } else {
      ..... for other browsers.........
 }
}
Shankar
  • 2,565
  • 8
  • 29
  • 56
  • Thanks for posting the solution to this issue. I suggest you try to mark your own answer to this question after 48 hrs when it is available to mark. It can help other community members in the future in similar kinds of issues. Thanks for your understanding. – Deepak-MSFT Apr 16 '20 at 02:51