locked
Cannot redirect the page after exporting and saving the excel file RRS feed

  • Question

  • User1888235789 posted

    hi

    I am exporting and saving the excel file. After saving the file the page is still doing some processing. To abort that processing i need to redirect the page. If I' redirect the page the SaveFileDilaog doesn't appear. If it appears at that time the page does not redirect. Please give some solution. THis is my code:

    ExportToCSVFile(DtExcel);
    Response.ContentType = "Application/x-msexcel";
    Response.AddHeader("content-disposition", "attachment;filename=" + GetCustomerUserID() + "_UserList.csv");
    Response.Write(ExportToCSVFile(DtExcel));
    // Context.ApplicationInstance.CompleteRequest();
    Response.Redirect("Redirect_Url_ExportToExcel.aspx", false);
    // Context.ApplicationInstance.CompleteRequest();
    // Response.End();

    Monday, September 29, 2014 1:16 AM

Answers

  • User753101303 posted

    Hi,

    Unclear.

    Redirect can't be used if you already sent some content (this information is part of an HTTP header and there is no point in sending some content if this is to move away immediately somewhere else).

    Anyway as you are sending back non html content type, the code you shown should trigger an open/save as dialog without replacing the current HTML markup shown in the browser (as what you sent is not text/html content). So there is no point to redirect somewhere are anyway you don't move away from what you previously shown.

    What is the problem if you don't redirect at all ? What is this processing? Is this something you do or is this some kind of behavior that is unexpected? We would need then to better understand what is the bad behavior you see to be able to suggest how to fix it (a redirection being liekly not the way to solve that).

    Ah could it be that you still send some HTML markup after having sent the Excel content?

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, September 29, 2014 8:45 AM