Click here to Skip to main content
11,645,087 members (65,445 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 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 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 700
1 494
2 Sergey Alexandrovich Kryukov 449
3 Afzaal Ahmad Zeeshan 444
4 CPallini 386
0 OriginalGriff 1,065
1 Sergey Alexandrovich Kryukov 683
2 DamithSL 681
3 Afzaal Ahmad Zeeshan 662
4 CPallini 555

Advertise | Privacy | Mobile
Web04 | 2.8.150731.1 | 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