Click here to Skip to main content
15,881,882 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have this code written to export data to excel in a click event. The export works fine except that the page is rendered blank on this button click.

Can somebody tell me what I am missing in this code..??

C#
protected void btnExportPDF_Click(object sender, EventArgs e)
        {

            if (!string.IsNullOrEmpty(hndPdfpath.Value))
            {
                // This is an important header part that informs the client to download this file.
                Response.AppendHeader("content-disposition", "attachment; filename=" + Path.GetFileName(hndPdfpath.Value));
                FileInfo flnInfo = new FileInfo(hndPdfpath.Value.Trim());
                if (flnInfo.Extension.ToLower() == ".xlsx" || flnInfo.Extension.ToLower() == ".xls")
                {
                    Response.ContentType = "application/Excel";
                }
                else
                {
                    Response.ContentType = "Application/pdf";
                }
                //Write the file directly to the HTTP content output stream.
                Response.WriteFile(hndPdfpath.Value);
            }
        }
Posted

1 solution

Hello,
For downloading file please use
C#
public void DownloadFile(string filePath)
{
..
}
from following link
ASP.NET File Upload with Progress Bar[^]
Thanks,
 
Share this answer
 
Comments
bbirajdar 3-Jun-13 10:25am    
Thank you for your efforts. But this did not work for me.. The page is still rendered blank

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900