Click here to Skip to main content
11,408,708 members (64,349 online)
Rate this: bad
Please Sign up or sign in to vote.
See more: C# ASP.NET file
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 2: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 at 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
0 OriginalGriff 390
1 Sergey Alexandrovich Kryukov 284
2 Maciej Los 155
3 Peter Leow 140
4 PIEBALDconsult 130
0 Sergey Alexandrovich Kryukov 8,626
1 OriginalGriff 6,855
2 Maciej Los 3,322
3 Abhinav S 3,238
4 Peter Leow 3,034

Advertise | Privacy | Mobile
Web04 | 2.8.150414.5 | Last Updated 3 Jun 2013
Copyright © CodeProject, 1999-2015
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