You must Sign In to post a response.
  • Category: .NET

    How to show popup when downloading excel file in asp.net using C#

    i have gridview data. i have one button called exporttoexcel when i click that button i want to export data into excel.

    my code as follows
    string attachment = "attachment; filename=GridviewDetails.xls";
    Response.ClearContent();
    Response.AddHeader("content-disposition", attachment);
    Response.ContentType = "application/vnd.ms-excel";
    Response.ContentType = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet";

    Response.Write("");
    Response.Write("<html xmlns:x=\"urn:schemas-microsoft-com:office:excel\">");
    Response.Write("<body>");
    Response.Write("<table border=1 bordercolor=black>");

    Response.Write("<tr>");
    Response.Write("<td colspan=5><b><center>");
    Response.Write("GirdviewDetails");
    Response.Write("</b></center></td>");
    Response.Write("</tr>");

    System.IO.StringWriter stringWrite = new System.IO.StringWriter();
    System.Web.UI.HtmlTextWriter htmlWrite = new HtmlTextWriter(stringWrite);

    GridView1.RenderControl(htmlWrite);
    Response.Write(stringWrite.ToString());

    Response.Flush();
    Response.Write("<table>");
    Response.Write("</body>");
    Response.Write("</html>");
    Response.End();

    When i click the export button the excel data is downloading directly,

    i want to show popup. in that popup open save is to be there.

    When i click the open button excel file to be opened.

    When i click the save button excel file to be saved.

    for that how can i do in asp.net using C#.
  • #765817
    download a file and open file is a client browser application, asp.net does not have any control on it, when browser prompt for download it has 3 button
    1. save
    2. Open
    3. cancel
    here if you click on open, the browser will open a file in temp folder and remove it when you close file, when you click on save it will save it in specified location
    I don't think there is a way to open a file after download

    Thanks
    Koolprasd2003
    Editor, DotNetSpider MVM
    Microsoft MVP 2014 [ASP.NET/IIS]

  • #765835
    Hi,

    I never tried this combination but I tried it separately, use modalpopupextender control in AJAX to achieve the confirmation with Yes / No option.
    You have to do more customization to achieve this task, while click save you need to perform the saving the file into temporary location same like for open you need to perform opening the file for one instance.

    please use below link to show the confirmation before perform any action.

    http://www.dotnetspider.com/resources/46217-ModalPopupExtender-with-Yes-No-options-without-postback.aspx

    --------------------------------------------------------------------------------
    Give respect to your work, Instead of trying to impress your boss.

    N@veen
    Blog : http://naveens-dotnet.blogspot.in/


  • Sign In to post your comments