How do I execute an action when I download a direct file in c #?


What I'm doing is a download of an Excel file when I find any record that already exists in the bd, this is mainly responsible for detecting it, not saving it and downloading an Excel indicating the repeating records, the problem begins when apart from doing that I execute a modal indicating that there have been records that could not be entered into the bd because they would be duplicated.

Current code:

Code C #:

        Page.ClientScript.RegisterStartupScript(GetType(), "hwa", "downloadError('Temp/ReportUsers" + FilesTemplate.Length + ".xlsx');", true);
        Response.ContentType = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet";
        Response.AddHeader("content-disposition", "attachment;filename=ReportUsers.xlsx");

JS Code:

 function downloadError(download) {
            title: "Repetido",
            template: 'danger',
            message: 'Hay llaves repetidas',
            buttonCancel: false,
            onOk: function() {


        $(".modal-body").html("<div class='text-center'><label style='font-size:12px;' >Hay llaves repetidas que no se pudieron insertar.</label><br/><a href='" + download + "'>Descargar llaves</a></div>");

In fact there is no execution of any action, whatever the reason and I do not know if it does not do postback when the download is made, the page stays there, but then how can I do an extra action after the download.

asked by David 16.11.2018 в 18:36

1 answer


Try to use third-party libraries that are responsible for downloading files, maybe some of them will provide you with an onComplete event which will notify you when the download is complete.

Here I leave some varied links, I hope they work for you or at least give you an idea of what you should do.





answered by 16.11.2018 в 19:59