Click here to Skip to main content
13,049,172 members (66,655 online)
Rate this:
Please Sign up or sign in to vote.
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..??

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";
                    Response.ContentType = "Application/pdf";
                //Write the file directly to the HTTP content output stream.
Posted 3-Jun-13 1:50am

1 solution

Rate this: bad
Please Sign up or sign in to vote.

Solution 1

For downloading file please use
public void DownloadFile(string filePath)
from following link
ASP.NET File Upload with Progress Bar[^]
aspnet_regiis -I 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)

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy | Mobile
Web02 | 2.8.170713.1 | Last Updated 3 Jun 2013
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100